X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/357027375ff8867f42ca34bcbfb5a78b5b185fc3..0def7bcb965d56cfa88c7e5a1676905b02f84ab6:/src/api/models.py?ds=inline diff --git a/src/api/models.py b/src/api/models.py index 5a3d42440..2481010be 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -2,6 +2,7 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +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 @@ -34,6 +35,22 @@ def _pre_delete_handler(sender, instance, **kwargs): else: category = None content_type = ContentType.objects.get_for_model(sender) - Deleted.objects.create(content_type=content_type, object_id=instance.id, - created_at=instance.created_at, category=category, slug=instance.slug) + Deleted.objects.create( + content_type=content_type, object_id=instance.id, created_at=instance.created_at, category=category, + slug=instance.slug) pre_delete.connect(_pre_delete_handler) + + +class BookUserData(models.Model): + book = models.ForeignKey(Book) + user = models.ForeignKey(User) + complete = models.BooleanField(default=False) + last_changed = models.DateTimeField(auto_now=True) + + def get_state(self): + return 'complete' if self.complete else 'reading' + + def set_state(self, state): + self.complete = state == 'complete' + + state = property(get_state, set_state)