Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Internet > HTTP (WWW)

    django-nested-forms 0.1.1

    Download button

    No screenshots available
    Downloads: 103  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Damien Szczyt | More programs
    Other/Proprietary Li... / FREE
    October 4th, 2011, 01:24 GMT
    ROOT / Internet / HTTP (WWW)

     Read user reviews (0)  Refer to a friend  Subscribe

    django-nested-forms description

    Nested forms for your Django projects

    django-nested-forms is a Django app that will help you to easily create nested forms in your project.

    Usage

    First of all, insert the nested_forms folder in in project's path.

    In your forms.py

    from nested_forms import ComplexModelForm

    Make you main form inherit from ComplexModelForm

    In Meta subclass of your ComplexModelForm, add :

    formsets = {
    }

    This dict has for keys the related objects' names.

    For the examples form Django's tutorial, we could write :

    def get_choice_form(poll):
     class ChoiceForm(forms.ModelForm):
     class Meta:
     model = Choice
     exclude = ['poll']

     def save(self, commit=True):
     instance = super(ChoiceForm, self).save(commit=False)
     instance.poll = poll
     if commit:
     instance.save()
     self.save_m2m()
     return instance

     return ChoiceForm

    class PollForm(ComplexModelForm):
     class Meta:
     model = Poll
     formsets = {
     'choice_set': {
     'form': lambda instance: get_choice_form(instance),
     'extra': 1,
     'initial': [
     {
     'choice': 'A sample choice',
     'votes': 0,
     }
     ],
     },
     }


    You now have a nested form. Let's start using it in your template.

    In your templates

    Considering your nested form instance in a form variable in your context, you can access your access your form fields like any other forms. Your formsets are accessible by {{ form.formsets.[ name of related name of your object] }}. Don't forget to add the management form for each, and each formset is like any formset you would create manually. DON'T FORGET TO IMPLEMENT THE "ADD" TEMPLATE FILTER !

    < form method="post" >
     < fieldset >
     < legend >Poll< /legend >
     {{ form.as_div }}

     {% with form.formsets.choice_set as choice_formset %}
     {{ choice_formset.management_form }}
     {% for choice_form in choice_formset.forms %}
     < fieldset >
     < legend >Choice {{ forloop.counter }}< /legend >
     {{ choice_form.as_div }}
     < /fieldset >
     {% endfor %}
     < button name="{{ choice_formset.prefix }}-TOTAL_FORMS" value="contact_formset.total_form_count|add:1" >
     Add a choice
     < /button >
     {% endwith %}
     < /fieldset >
     < input type="submit" value="Save poll"/ >
    < /form >


    Product's homepage

    Requirements:

    · Python
    · PCEkspert.com Forum Meni

      


    TAGS:

    Django projects | nested forms | Django | nested | forms

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM