+
+
+class BookUserData(models.Model):
+ book = models.ForeignKey(Book)
+ user = models.ForeignKey(User)
+ complete = models.BooleanField(default=False)
+ last_changed = models.DateTimeField(auto_now=True)
+
+ @property
+ def state(self):
+ return 'complete' if self.complete else 'reading'
+
+ @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