[Python] JsonField in Django Admin as Inline

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a JsonField in my Model, its structure is a dict.

    class MyModel:
    final_result = models.JSONField()


    But it's pretty big, and it's hard to edit it with any JSON widget. So I thought, that maybe I need to parse/split it to several 'custom' fields.

    jsonfield = {
    "key1": "value1",
    "key2": "value2",
    "key3": [
    {"inner_key_1": "inner_value_1", "inner_key_2": "inner_value_2", etc}
    ]
    }


    Given this JSON data, I would like to have fields: key1, key2 (which is easy), and here's the problem - key3, which is list of dicts.

    Can I somehow display them like Inlines? With fields - inner_key_1, inner_key_2 (etc) So I can

    • edit each element of list
    • delete element with button
    • add another element with preset fields

    When I try to use inlines - it says it needs a model, but I don't have a model for this json. Proxy models and abstract models give errors. Forms, formsets (AI recommendations) don't work too.

    I tried using inlines, forms, formsets, with a help from AI))

    Continue reading...

Compartilhe esta Página