class TopicRead(models.Model): """ This model tracks the last post read in a topic by a user. Technically it is a simple joint [user, topic, last read post]. """ class Meta: verbose_name = 'Sujet lu' verbose_name_plural = 'Sujets lus' unique_together = ('topic', 'user') topic = models.ForeignKey(Topic, db_index=True) post = models.ForeignKey(Post, db_index=True) user = models.ForeignKey(User, related_name='topics_read', db_index=True) objects = TopicReadManager() def __str__(self): return "<Sujet '{0}' lu par {1}, #{2}>".format(self.topic, self.user, self.post.pk)
class TopicRead(models.Model): """ This model tracks the last post read in a topic by a user. Technically it is a simple joint [user, topic, last read post]. """ class Meta: verbose_name = 'Sujet lu' verbose_name_plural = 'Sujets lus' # TODO: ça a l'air d'être OK en base, mais ne devrait-il pas y avoir une contrainte unique sur (topic, user) ? topic = models.ForeignKey(Topic, db_index=True) post = models.ForeignKey(Post, db_index=True) user = models.ForeignKey(User, related_name='topics_read', db_index=True) objects = TopicReadManager() def __unicode__(self): return u'<Sujet "{0}" lu par {1}, #{2}>'.format( self.topic, self.user, self.post.pk)
class TopicRead(models.Model): """ This model tracks the last post read in a topic by a user. Technically it is a simple joint [user, topic, last read post]. """ class Meta: verbose_name = "Sujet lu" verbose_name_plural = "Sujets lus" unique_together = ("topic", "user") topic = models.ForeignKey(Topic, db_index=True, on_delete=models.CASCADE) post = models.ForeignKey(Post, db_index=True, on_delete=models.CASCADE) user = models.ForeignKey(User, related_name="topics_read", db_index=True, on_delete=models.CASCADE) objects = TopicReadManager() def __str__(self): return f"<Sujet '{self.topic}' lu par {self.user}, #{self.post.pk}>"