X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8952b9530d943655e552ea660c47e850123c5105..7bbeecb5dd5c5f20120f9e40e41568a3bff1caa4:/src/api/models.py?ds=sidebyside diff --git a/src/api/models.py b/src/api/models.py index 28bc8807d..ff1f09a0d 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -1,19 +1,18 @@ -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.db import models from django.db.models.signals import pre_delete -from django.utils.translation import ugettext_lazy as _ from catalogue.models import Book, Tag class Deleted(models.Model): object_id = models.IntegerField() - slug = models.SlugField(_('slug'), max_length=120, blank=True, db_index=True) + slug = models.SlugField('slug', max_length=120, blank=True, db_index=True) content_type = models.ForeignKey(ContentType, models.CASCADE) category = models.CharField(max_length=64, null=True, blank=True, db_index=True) created_at = models.DateTimeField(editable=False, db_index=True) @@ -50,6 +49,9 @@ class BookUserData(models.Model): complete = models.BooleanField(default=False) last_changed = models.DateTimeField(auto_now=True) + class Meta: + unique_together = [('user', 'book')] + @property def state(self): return 'complete' if self.complete else 'reading' @@ -110,7 +112,7 @@ class Token(models.Model): settings.AUTH_USER_MODEL, models.CASCADE, null=True, blank=True, related_name='tokens' ) - consumer = models.ForeignKey(Consumer, models.CASCADE) + consumer = models.ForeignKey(Consumer, models.CASCADE, null=True, blank=True) def __str__(self): return "%s Token %s for %s" % (self.get_token_type_display(), self.key, self.consumer)