Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mujad opened this issue Oct 11, 2022 · 5 comments
Open

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

mujad opened this issue Oct 11, 2022 · 5 comments

Comments

@mujad
Copy link

mujad commented Oct 11, 2022

  • django-json-widget version: 1.1.1
  • Django version: 4.0.7
  • Python version: 3.9
  • Operating System: ubuntu 20.04

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
Copy link

tadamcz commented Nov 29, 2023

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
Copy link

tadamcz commented Jan 31, 2024

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
Copy link

abe-101 commented May 20, 2024

Have you found a work-a-round?

@jg-valdes
Copy link

It's working for me on release v2.0.1 I am using Django 5.1 and python 3.12, also I am using unfold as admin template.

@vathzen
Copy link

vathzen commented Jan 17, 2025

Has anyone found a workaround for this? I'm using Django 5.1 and v2.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants