Models Mixin Inherit Many to Many

8 views
Skip to first unread message

sebasti...@gmail.com

unread,
Jun 4, 2021, 1:19:33 PM6/4/21
to Django users
Hello,

i need a mixin where i can inherit many to many like this:

mixin.py:

class RightsModelRelation(models.Model):

    user_link = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=False, default=None,
                                    related_name="%(class)s_rights_user")
    right_to_view = models.BooleanField(default=True)
    right_to_change = models.BooleanField(default=False)
    right_to_delete = models.BooleanField(default=False)


class RightsModelMixin(models.Model):
    owner = models.ForeignKey(User, on_delete=models.CASCADE, null=False, default=None,
                              related_name="%(class)s_owner", )
    rights_link = models.ManyToManyField(RightsModelRelation, default=None,
                                         related_name="%(class)s_rights_link")

and in my normal model.py i want:

class Address(RightsModelMixin,models.Model):
    lastname = models.CharField(max_length=255, default="", )
    firstname = models.CharField(max_length=255, default="", blank=True, null=True)


On migrations i get:

You are trying to add a non-nullable field 'rightsmodelmixin_ptr' to address without a default; we can't do that (the database needs something to populate existing rows).

Reply all
Reply to author
Forward
0 new messages