I've seen many discussions about django-guardian use with django-polymorphic, but it's verry confusing for me.
Imagine this case:
class FeedPost(PolymorphicModel):
class Meta:
default_permissions = ('add', 'change', 'delete', 'view')
class ArticleFeedPost(FeedPost):
class Meta:
default_permissions = ('add', 'change', 'delete', 'view')
With django-guardian 1.4.6, when you set permisssions to ArticleFeedPost, these permissions doesn't apply to FeedPost.
In the doc, there is this about polymorphic objects:
http://django-guardian.readthedocs.io/en/stable/configuration.html?highlight=polymorph#guardian-get-content-type
But there is no example describing how to use get_default_content_type.
My questions are (by the way, I'm sorry to ask these questions here, but I have a better chance to have a reply here than elsewhere):
Hello,
It is a django-polymorphic issue specific. django-polymorphic
contains code for support django-guardian, so look for django-polymorphic docs about support.
Greetings,
CC: @benkonrath
Regarding issues of versioning is pleased to announce that it accepts the attention. In the next releases will be corrected. GUARDIAN_GET_CONTENT_TYPE
was released in django 1.4.6.
@BenDevelopment The function to retrieve the base model content type was only recently merged into django-polymorphic. Using the base model content type will make the guardian permissions work on the base model. You just need to add this setting if you're using the latest released version of django-guardian and the latest version of django-polymorphic from git:
GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.get_polymorphic_base_content_type'
You can also copy & paste the get_polymorphic_base_content_type
code into your own project if you don't want to use the latest git version of django-polymorphic.
Here are the unreleased docs:
https://django-polymorphic.readthedocs.io/en/latest/third-party.html#django-guardian-support
@BenDevelopment Correction, the setting should be:
GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.guardian.get_polymorphic_base_content_type'
I'm going to make a PR to polymorphic to fix this in the docs.
Thank you guys! All works well 馃憤 馃挴 !