X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/362e390a3a0948ed3c2aa54b966a898e90b231a3..b09ddc60e118508d96906f26ecb0e1709ca89f1b:/src/social/models.py diff --git a/src/social/models.py b/src/social/models.py index c8d0d1023..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) @@ -436,6 +436,11 @@ class UserListItem(Syncable, models.Model): 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'):