【发布时间】:2014-04-03 06:10:17
【问题描述】:
我有一个论坛应用。它具有 Tag、Question 和 Answer 三个类。
型号:
class Tag(models.Model):
tag_name = models.CharField(max_length=100)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=True, auto_now=False)
description = models.TextField()
def __unicode__(self):
return smart_unicode(self.tag_name)
class Question(models.Model):
short_description = models.CharField(max_length=250)
description = models.TextField()
asked_by = models.ForeignKey(User)
tags = models.ManyToManyField(Tag)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=True, auto_now=False)
def __unicode__(self):
return smart_unicode(self.short_description)
class Answer(models.Model):
description = models.TextField()
for_question = models.ForeignKey(Question)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=True, auto_now=False)
def __unicode__(self):
return smart_unicode(self.description)
我还想为 Question、Answers 以及我的应用程序的其他部分 提供 cmets。实现这一目标的最佳方法是什么?我的意思是,为这个用例设计 django 模型的正确方法是什么?我必须为此使用内容类型吗?
【问题讨论】:
-
Django自带cmets模型,docs.djangoproject.com/en/dev/ref/contrib/comments能满足你的需求吗?
-
我想,它已被弃用。但我检查了网址,并不太喜欢这个
comment framework has been deprecated and is no longer supported. Most users will be better served with a custom solution。你能告诉我其他方式吗? -
罗宾,你是怎么回答下面这个问题的?
-
@halfer 我最终使用了通用外键。
-
请您添加一个答案,然后以某种方式承认克雷格的努力?无视他们的善意是不礼貌的。
标签: django django-models django-contenttypes