X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/572ee91a188114e383712eac2426dab3bcef6c00..b09ddc60e118508d96906f26ecb0e1709ca89f1b:/src/social/models.py diff --git a/src/social/models.py b/src/social/models.py index 89fa65cd8..a8bec9cd5 100644 --- a/src/social/models.py +++ b/src/social/models.py @@ -11,7 +11,7 @@ from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.core.mail import send_mail from django.urls import reverse -from django.utils.timezone import now, utc +from django.utils.timezone import now from catalogue.models import Book from catalogue.utils import get_random_hash from wolnelektury.utils import cached_render, clear_cached_renders @@ -418,11 +418,11 @@ class UserList(Syncable, models.Model): class UserListItem(Syncable, models.Model): list = models.ForeignKey(UserList, models.CASCADE) uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False, blank=True) - order = models.IntegerField() + order = models.IntegerField(default=0) deleted = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) - reported_timestamp = models.DateTimeField() + reported_timestamp = models.DateTimeField(default=now) book = models.ForeignKey('catalogue.Book', models.SET_NULL, null=True, blank=True) fragment = models.ForeignKey('catalogue.Fragment', models.SET_NULL, null=True, blank=True) @@ -433,6 +433,14 @@ class UserListItem(Syncable, models.Model): syncable_fields = ['order', 'deleted', 'book', 'fragment', 'quote', 'bookmark', 'note'] + objects = ActiveManager() + all_objects = models.Manager() + + def save(self, *args, **kwargs): + if not self.order: + self.order = self.list.userlistitem_set.all().count() + 1 + super().save(*args, **kwargs) + @classmethod def create_from_data(cls, user, data): if data.get('favorites'):