You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In cases where a ParentalManyToManyField is defined on a mixin class that's to be inherited in both Wagtail Pages and raw Django Models, the PageAwareParentalManyToManyField may be used. I don't remember where I got this code from (or if I created it or not!), but it works great and I thought I'd share:
classPageAwareParentalManyToManyField(ParentalManyToManyField):
""" A ManyToManyField that is aware of if it is being used on a page or a non-page model. When uses on a page, it will perform as a ParentalManyToManyField, otherwise it will perform as a regular ManyToManyField. """defcontribute_to_class(self, cls, name, **kwargs):
ifissubclass(cls, (AbstractPage, PageBase)):
super().contribute_to_class(cls, name, **kwargs)
else:
super(ParentalManyToManyField, self).contribute_to_class(cls, name,
**kwargs)
defvalue_from_object(self, obj):
ifisinstance(self.model, (AbstractPage, PageBase)):
returnsuper().value_from_object(obj)
else:
returnsuper(ParentalManyToManyField, self).value_from_object(obj)
The text was updated successfully, but these errors were encountered:
In cases where a
ParentalManyToManyField
is defined on a mixin class that's to be inherited in both Wagtail Pages and raw Django Models, thePageAwareParentalManyToManyField
may be used. I don't remember where I got this code from (or if I created it or not!), but it works great and I thought I'd share:The text was updated successfully, but these errors were encountered: