X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0def7bcb965d56cfa88c7e5a1676905b02f84ab6..a791ae7c71b918ca39e7083209019de03a164252:/src/api/models.py?ds=inline diff --git a/src/api/models.py b/src/api/models.py index 2481010be..d2716b922 100644 --- a/src/api/models.py +++ b/src/api/models.py @@ -47,10 +47,13 @@ class BookUserData(models.Model): complete = models.BooleanField(default=False) last_changed = models.DateTimeField(auto_now=True) - def get_state(self): + @property + def state(self): return 'complete' if self.complete else 'reading' - def set_state(self, state): - self.complete = state == 'complete' - - state = property(get_state, set_state) + @classmethod + def update(cls, book, user, state): + instance, created = cls.objects.get_or_create(book=book, user=user) + instance.complete = state == 'complete' + instance.save() + return instance