Title: Django Admin Inline objects
Tags: django;admin;inline
Question: I'm completely new to Django coming from PHP and therefore struggling a little with the terminology.  This makes searching for an answer quite hard. Hopefully, somebody can tell me if this can be done within the excellent Django admin.
Ok, so the idea is that I have a questionaire which will be filled in by members of the design world.  The questionaire class has very few fields, title, introduction, date.
The questions have their own class, there is a limited number in this case 20 and they are the same on each questionaire.
Therefore I have an answers class, the answer belongs to both a questionaire and a question.
class Questionaire(models.Model):
title = models.CharField(max_length=255)
intro = models.TextField(max_length=4000)
date_entered = models.DateField()
date_modified = models.DateField()
def __unicode__(self):
return self.title
class Question(models.Model):
title = models.CharField(max_length=255)
number = models.IntegerField()
def __unicode__(self):
return self.title
class Answer(models.Model):
response = models.TextField(max_length=4000)
questionaire = models.ForeignKey('articles.Questionaire')
question = models.ForeignKey('articles.Question')
def __unicode__(self):
return self.response
Sorry about the formatting above
What I am needing in the Questionaire admin is for each question, an answer field is available inline.  If possible with the question name as the form field name.
Is this possible within Django admin?
Would be most grateful for any assistance
Comment: The answer to http://stackoverflow.com/questions/702637/django-admin-inline-inlines-or-three-model-editing-at-once may be of use to you.


Here is another answer: See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects
class AnswerInlineAdmin(admin.StackedInline):
model = Answer
extra = 1
class QuestionAdmin(admin.ModelAdmin):
...
inlines = [AnswerInlineAdmin]
Comment for this answer: The admin doesn't support inlines within inlines at this time. You can do inline answers on the question change form, and inlines questions on the questionaire change form. But not both simultaneously.
Comment for this answer: Thanks for attempt Chris but this doesnt really work for me.  I have 20 set questions.  I need an answer field for each question to appear in the questionnaire, ideally with the question title appearing as the formfield for each answer.  Your suggestion adds a single answer field and then I have a dropdown to choose the question.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2012:00:03/22/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<django><admin><inline>', 'Title': 'Django Admin Inline objects', 'ViewCount': 2229, 'id': 9828421, 'user_AboutMe': None, 'user_AccountId': 1001423.0, 'user_DisplayName': 'user1016190', 'user_Reputation': 113.0, 'user_Views': 12.0, 'user_id': 1016190.0}}