在 django admin 中使用 1:n 关系
我想在 Django 中构建一个问题并使用 Django 的管理界面来输入数据。 站点管理员应该能够设置新的问题问卷。定义模型,其中的问题始终与问题相关,这是没有问题的:
class Questionary(models.Model):
title = models.CharField(max_length=50)
def __unicode__(self):
return self.title
class Question(models.Model):
text = models.CharField(max_length=150)
questionary = models.ForeignKey(Questionary)
def __unicode__(self):
return self.text
使用它,我可以在管理中创建和编辑问题(但只有标题)。我还可以编辑与问题相关的每个问题。但一次只能问一个问题。
有没有办法将模型(或管理区域的一部分)设置为在管理界面中将“问题部分”置于顶部并在其下方设置问题?有添加和删除问题的按钮吗?
非常感谢,
mfapl
I want to build a questionary in Django and use django's admin-interface to enter the data.
The site-admin should be able to set-up new questionaries with questions. Define models which questions have always a querstionary in relation is no problem:
class Questionary(models.Model):
title = models.CharField(max_length=50)
def __unicode__(self):
return self.title
class Question(models.Model):
text = models.CharField(max_length=150)
questionary = models.ForeignKey(Questionary)
def __unicode__(self):
return self.text
Using this I can create and edit questionaries (but only it's title) in the admin. Also I can edit every single Question with an relation to the questionary. But only one question a time.
Is there a way to set up the models (or a part of the admin-area) to have the "questionary-part" at the top and the questions below that in the admin-interface? With buttons to add and delete questions?
Thanks a lot,
mfapl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以,看看 InlineModelAdmin< /a>
Yes you can, take a look at InlineModelAdmin