Hi
is posible fill forms with initial values for example

------ models.py ---------
class Model1(models.Model):
    field1 = models.CharField()
    field2 =models.CharField()

CHOICE_ONE = (
      (1,'one'),
      (2, 'two'),
      (3, 'three'),
      (4, 'four')
)
class Model2(models.Model):
     field_fk = fk(Model1)
     field2 = models.IntegerField(choices=CHOICE_ONE)
     field3 = IntegerField()
     field4 = IntegerField()

----- forms.py -----------

class Model2Form(forms.ModelForm):

    class Meta:
        model = Model2
        exclude = ('field_fk',)

---------- views.py --------------

def name_views(request):
    initial_one = [{'field2':'one'},
                        {'field2':'two'},
                        {'field2':'three '},
                        {'field2':' four'},
                       ]
    form1FormSet = modelformset_factory(Model2, formModel2Form=,extra=4)
    if request.method == "POST":
        form1 = Model2Form(request.POST)
        if form1.is_valid():
            form1.save()
   else:
        form1 = form1FormSet(initial=initial_one)

    return render_to_response('template_form1.html',{'form1':form1},
                              context_instance=RequestContext(request))

------ template_form1.html --------

       {% csrf_token %}
      {{form1.management_form}}

      {%for fila in form1.forms%}
               {{ fila }}<br>
      {%endfor%}

but this no working the output is

[image: Inline image 1]
but i need to appear so

[image: Inline image 2]

the words in red are the options

which is the right way to do better and if possible do that

additionally I read this but it's not like my model
https://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-initial-data-with-a-formset

Cheers

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<<Selection_001.png>>

<<Selection_001.png>>

Reply via email to