我有两种模式:
class Question (models.Model):
question = models.CharField(max_length=100)
hobby = models.ForeignKey(Hobby)
def __unicode__(self):
return self.question
class Answer (models.Model):
answer = models.CharField(max_length=1000)
attach_file = models.FileField(upload_to='Attachments', blank=True)
question = models.OneToOneField(Question)
def __unicode__(self):
return self.answer
我正在尝试使用Answer表单构建一个列出Question对象的页面(类似于Django Admin站点视图)。如同:
问题1 - 答案1:[文本框],[可选附件]
问题2 - 答案2:[文本框],[可选附件]
* * *
问题n - 答案n:[文本框],[可选附件]
我首先想的是我是否可以使用formset和查询来完成它:
query=Answer.objects.filter("all answer objects that are related to all question objects related to "hobby1")
但还未能弄明白。