Collection remove the redundant mainItem model attr.

This commit is contained in:
Tom Hacohen
2020-04-16 11:28:49 +03:00
parent 0fbc5c104c
commit a72543f6c9
3 changed files with 23 additions and 5 deletions

View File

@@ -29,7 +29,6 @@ class Collection(models.Model):
max_length=44, validators=[UidValidator])
version = models.PositiveSmallIntegerField()
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
mainItem = models.OneToOneField('CollectionItem', related_name='of_collection', null=True, on_delete=models.SET_NULL)
class Meta:
unique_together = ('uid', 'owner')
@@ -37,9 +36,13 @@ class Collection(models.Model):
def __str__(self):
return self.uid
@cached_property
def main_item(self):
return self.items.get(uid=None)
@cached_property
def content(self):
return self.mainItem.content
return self.main_item.content
class CollectionItem(models.Model):