I've got it (I think):
http://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-more-than-one-formset-in-a-view

On szept. 9, 18:49, Viktor <viktor.n...@gmail.com> wrote:
> hi,
>
> how can I create a page similar to the admin pages in the sense of
> having a ModelForm and a formset generated with
> generic_inline_formset_factory, that is model instances related to my
> "base" model with the content_types framework?
>
> I have two models:
>
> class Project(models.Model):
>
>     title = models.CharField(max_length=255)
>     customer = models.ForeignKey(User)
>     language_from = models.ForeignKey(Language,
> related_name='language_from')
>     language_to = models.ForeignKey(Language,
> related_name='language_to')
>     deadline = models.DateTimeField(null=True)
>     revenue = models.OneToOneField(Revenue, null=True)
>     comment = models.TextField(blank=True)
>     accepted = models.BooleanField(default=False)
>     closed = models.BooleanField(default=False)
>     created = models.DateTimeField(auto_now_add=True)
>     files = generic.GenericRelation('File')
>
> class File(models.Model):
>
>     content_type = models.ForeignKey(ContentType)
>     object_id = models.PositiveIntegerField()
>     content_object = generic.GenericForeignKey()
>
>     file = models.FileField(upload_to=get_file_upload_to)
>     comment = models.TextField(blank=True)
>     created = models.DateTimeField(auto_now_add=True)
>
> and a form
>
> class ProjectForm(forms.ModelForm):
>
>     customer = forms.IntegerField(widget=forms.HiddenInput, initial=0)
>
>     class Meta:
>         model = models.Project
>         exclude = ['revenue', 'closed', 'accepted']
>
> I can create a form wizard, and add ProjectForm at its first page, and
> the following formset at the second
>
> ProjectFilesFormSet = generic_inlineformset_factory(models.File,
> exclude=['created'], can_delete=False)
>
> but how can I do it on one page? I'm sure that I miss something, as
> ProjectFilesFormSet by default is a subclass of
> BaseGenericInlineFormSet, thus it should be possible to be used
> "inline".
>
> Can I combine an instance of ProjectFrom and ProjectFilesFormSet on
> the same page? Should I do it in the view function by calling first
> myProjectForm.save and then ProjectFiledFormSet.save, or is there a
> better way?
> If so, how can I assure that the ProjectForm won't get written to the
> database until the Files are saved?
>
> I know these are quite a few question, and I would be happy to get
> answers even to a subset of them.
>
> Thank you, Viktor
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to