2

So I have a model Member:

class Member(models.Model):
    first_name = models.CharField(max_length = 15)
    last_name = models.CharField(max_length = 15)
    house = models.ForeignKey('House', null = True)
    created_on = models.DateTimeField('created on')
    user = models.OneToOneField(User, null = True)

and a form to create the model:

class MemberForm(forms.Form):
    first_name = forms.CharField()
    last_name = forms.CharField()
    email_address = forms.EmailField()

My app works where you create a House and specify the number of Members in your house. That's as far as I have working, but I would like it to continue to a new page where it displays an appropriate number of forms (one for each Member), and then creates a Member instance for each with the supplied data. I'm confused as to how I access the data from each form, since they're all technically in the same HTML form. More specifically how I identify what email field goes with which first name field and so on. Any help would be greatly appreciated, thanks.

2
  • Just a small suggestion, you really do not need first_name and last_name on this model except you really need these for a special reason. Since you got a relation to the User Model anyway which contains these field. This maybe one more database hit to retrieve the names, but this would also occur if you query the user object anyway... Commented Aug 19, 2013 at 21:30
  • I definitely appreciate what you're saying and I've considered it but with what I'm doing I think having the first and last name fields are a necessary redundance. Commented Aug 19, 2013 at 22:00

1 Answer 1

2

This is what formsets are for.

Note that creating a member from a memberform would be easier if you used model forms (and model formsets).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.