Consider I have a Django model with a custom JSONField
as below,
# models.py
class JSONCustomField(models.JSONField):
...
class JSONFieldModel(models.Model):
json_field = JSONCustomField(default=list)
This model is connected via Django Admin
# admin.py
@admin.register(JSONFieldModel)
class JSONFieldModelAdmin(admin.ModelAdmin):
def expected_json(self: JSONFieldModel):
return self.json_field
list_display = ("id", "json_field", expected_json)
This setup resulting an output like the below,
Questions
Why
JSON FIELD
andEXPECTED JSON
display different results in Django Admin? (It's supposed to be the same, right?)How can I tell Django to parse and display my "list of strings" to "comma separated strings" as
EXPECTED JSON
represents? That is, how to tell Django to give me result asEXPECTED JSON
while adding the custom field to the ModelAdmin as a string ("json_field") in Django Admin
Notes
- Django version
3.2.X
- Assume that the
json_field
will only acceptlist
inputs (Just like anArrayField
)