'DjangoModelPermissions ignore my added permissions

I have a problem with DjangoModelPermissions. It works fine with standard permissions but not with permissions I added to the Meta of my model.

Example:

class MarketingImage(MarketingMediaAbstract):

    image = models.ImageField(_('Marketing image'), upload_to="marketing/images/")
    machine = models.ForeignKey("machine.Machine", 
                            verbose_name = _("machine"),
                            related_name="marketing_image_machine",
                            on_delete=models.CASCADE) 
    
    class Meta:
        verbose_name = _("Marketing Image")
        verbose_name_plural = _("Marketing Images")
        permissions = [('change_marketingmedia', 'Can change Marketing Media'),
                       ('delete_marketingmedia', 'Can delete Marketing Media'),
                       ('add_marketingmedia', 'Can add Marketing Media'),
                       ('view_marketingmedia', 'Can view Marketing Media')]

When I migrated this object, 4 permissions were created:

  • view_marketingimage
  • add_marketingimage
  • change_marketingimage
  • delete_marketingimage

When I use permission_classes = [DjangoModelPermission], it's works with *_marketingimage but not with *_marketingmedia

*_marketingmedia are ignored.

How do I get DjangoModelPermission to work with the permissions I added?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source