I have a simple-ish ownership design on one of my models. It can be owned by multiple people and current owners can add other people but they have to confirm the invite before they are treated as a real owner.
class MyOwnedThing(models.Model):
owners = models.ManyToManyField(User, through='Ownership', related_name='othings')
def is_owner(self, user):
return user in self.owners
class Ownership(models.Model):
user = models.ForeignKey(User)
myownedthing = models.ForeignKey(MyOwnedThing)
confirmed = models.BooleanField(default=False)
The problem is MyOwnedThing.is_owner
needs to check that the owner had confirmed their invite. Is there a simple way of doing that or am I left doing a separate try/except around Ownership.objects.filter(user=u, myownedthing=mot, confirmed=True)
?