【发布时间】:2011-07-16 11:50:08
【问题描述】:
前言:我有两个模型(Product 和UserProfile),我想实现一个我的 cmets 系统。评论与对象相关,Product 或 UserProfile。
class Product(models.Model):
name = models.CharField(max_length = 40)
comments = models.ManyToMany(Comment)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique = True)
comments = models.ManyToMany(Comment)
class Comment(models.Model):
text = models.TextField()
author = models.ForeignKey(User)
timestamp = models.DateTimeField(auto_now_add = True)
这些模型下的逻辑是否正确?我很怀疑,因为这种方式意味着Product 可以有很多 cmets(这是正确的),但Comment 可以有很多产品(我不认为这是正确的)。
不是吗?
【问题讨论】:
标签: python django django-models django-orm