wagtail-nest / wagtail-modeladmin

Add any model in your project to the Wagtail admin. Formerly wagtail.contrib.modeladmin.
Other
22 stars 8 forks source link

Modeladmin doesn't discover proxy models #16

Open thorin-schiffer opened 5 years ago

thorin-schiffer commented 5 years ago

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.

Technical details

ababic commented 5 years ago

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 commented 5 years ago

Looks good to me! Thank you for researching :)