Using 1:n relations in django admin
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 Qu开发者_如何学Cestionary(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
Yes you can, take a look at InlineModelAdmin
精彩评论