That's exactly what I need!!! Thank you!
On Wed, Jul 21, 2010 at 12:15 AM, Ivan <ivan.t...@gmail.com> wrote: > http://charlesleifer.com/blog/djangos-inlineformsetfactory-and-you/ > might be the one you're looking for. > > Cheers, > Ivan > > > > On Wed, Jul 21, 2010 at 7:30 AM, Renne Rocha <rennero...@gmail.com> wrote: >> Hello all, >> >> I want to create a page that the user will be able to include one >> 'Project', and several 'Ports' (related to this project). But I am >> having problems saving the Ports form, because the project_id isn't in >> the form yet. >> >> I have the following models: >> >> class Project(models.Model): >> name = models.CharField(max_length=100) >> >> class Port(models.Model): >> description = models.CharField(max_length=20) >> project = models.ForeignKey(Project) >> >> And the following forms: >> >> class ProjectForm(ModelForm): >> class Meta: >> model = Project >> >> class PortForm(ModelForm): >> class Meta: >> model = Port >> widgets = { >> 'project': HiddenInput() # Hidden because I can't choose >> the project yet >> } >> >> And in the view that generate my form I have: >> def new_project(request): >> PortFormSet = formset_factory(PortForm) >> if request.method == 'POST': >> project_form = ProjectForm(request.POST) >> port_formset = PortFormSet(request.POST) >> if project_form.is_valid(): >> new_project = project_form.save() # I have my new >> 'Project' instance here >> >> for port_form in port_formset.forms: >> # Here is my problem >> if port_form.is_valid(): # Always return false because >> I haven't set the project_id >> ????? # What should I put here to define the project_id? >> port_form.save() >> return HttpResponseRedirect('/projects/') >> else: >> # Create the form and return to the template >> >> Thank you! >> >> Renne Rocha >> renne.ro...@gmail.com >> http://www.linkedin.com/in/rennerocha >> +55 19 8154-9345 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.