jmrivas86 / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
MIT License
433 stars 88 forks source link

Its no work when you make your model admin readonly #71

Open mujad opened 1 year ago

mujad commented 1 year ago

Description

when I make my model readonly widget not work !

`class ReadOnlyAdminModel(admin.ModelAdmin): formfield_overrides = { models.JSONField: {'widget': JSONEditorWidget}, }

def has_add_permission(self, request):
    return False

def has_change_permission(self, request, obj=None):
    return False

def has_delete_permission(self, request, obj=None):
    return False

`

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
tadamcz commented 9 months ago

I can confirm I'm still having this issue.

Is it possible this should be fixed in Django itself? It looks like when you make a field read-only it shows a plain-text representation instead of the appropriate widget. It would make more sense if Django modified only the default widget when a field is set to read-only.

I briefly looked at the Django docs and didn't see anything to suggest this is intended behaviour.

tadamcz commented 7 months ago

This StackOverflow answer (from 2013) seems to confirm it's a Django behaviour:

When field is set to readonly, Django uses display_for_field function which hardcodes the result, you can't customize it.

https://stackoverflow.com/a/14833606/

abe-101 commented 4 months ago

Have you found a work-a-round?