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

Modeladmin doesn't discover proxy models #16

Open
thorin-schiffer opened this issue Nov 19, 2018 · 2 comments
Open

Modeladmin doesn't discover proxy models #16

thorin-schiffer opened this issue Nov 19, 2018 · 2 comments

Comments

@thorin-schiffer
Copy link

Issue Summary

Modeladmin PermissionHelper looking up for permission objects with self.opts.app_label/self.opts.model_name, which is not correct for proxy models.

Steps to Reproduce

  1. start new project
  2. declare custom model in models.py, which extends existing model using proxy model mechanism
  3. declare custom model admin for that model
  4. admin won't show up in the menu

looks like PermissionHelpers method get_all_model_permissions returns empty queryset, because its looking up as:

Permission.objects.filter(
            content_type__app_label=self.opts.app_label,
            content_type__model=self.opts.model_name,
        )

but permissions for proxy models would refer to the parent model (see https://stackoverflow.com/questions/15037642/django-proxy-model-permissions-do-not-appear)

so probably the correct way would be to use parent's meta in __init__:

...
        self.opts = model._meta if not model._meta.proxy else ????
...

???? should be replaced with a upwards lookup for non proxy model in the hierarchy.

  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: no

Technical details

  • Python version: Run 3.6.6.
  • Django version: 2.0.9
  • Wagtail version: 2.1.3
@ababic
Copy link

ababic commented Dec 12, 2018

Thanks for reporting @eviltnan. I've added a PR (#4952) to address this, if you'd like to take a look / comment? Just awaiting on feedback from core team members.

@thorin-schiffer
Copy link
Author

Looks good to me! Thank you for researching :)

@laymonage laymonage transferred this issue from wagtail/wagtail Jul 26, 2023
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

Successfully merging a pull request may close this issue.

2 participants