Friday, June 4, 2021

Models Mixin Inherit Many to Many

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).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5ae24367-e341-4ecc-9d7e-d204d866de6dn%40googlegroups.com.

No comments:

Post a Comment