Skip to content

TimBest/django-multi-form-view

Repository files navigation

Django Multi. Form View

CircleCI codecov PyPI PyPI

Django class based views for using more than one Form or ModelForm in a single view.

Install

$ pip install django-multi-form-view

Example

from multi_form_view import MultiModelFormView class RecordFormView(MultiModelFormView): form_classes = { 'photo_form' : PhotoForm, 'record_form' : RecordForm } record_id=None template_name = 'records_form.html' def get_objects(self): self.record_id = self.kwargs.get('record_id', None) try: record = Record.objects.get(id=self.record_id) except Record.DoesNotExist: record = None return { 'record_form': record, 'photo_form': record.photo if record else None } def get_success_url(self): return reverse('records') def forms_valid(self, forms): photo = forms['photo_form'].save() record = forms['record_form'].save(commit=False) record.photo = photo record.save() return HttpResponseRedirect(self.get_success_url())

Demo

$ cd demo $ pip install -r requirements.txt $ python manage.py migrate $ python manage.py runserver

Testing

$ python demo/manage.py behave

About

Django class based views for using more than one form in a single view

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7