formset

Django formset unit test

这一生的挚爱 提交于 2019-11-30 13:00:19
问题 I can't running Unit Test with formset. I try to do a test: class NewClientTestCase(TestCase): def setUp(self): self.c = Client() def test_0_create_individual_with_same_adress(self): post_data = { 'ctype': User.CONTACT_INDIVIDUAL, 'username': 'dupond.f', 'email': 'new@gmail.com', 'password': 'pwd', 'password2': 'pwd', 'civility': User.CIVILITY_MISTER, 'first_name': 'François', 'last_name': 'DUPOND', 'phone': '+33 1 34 12 52 30', 'gsm': '+33 6 34 12 52 30', 'fax': '+33 1 34 12 52 30', 'form-0

Django accessing formset data

自闭症网瘾萝莉.ら 提交于 2019-11-30 09:17:46
I'm having difficulty accessing the data submitted through my formset. Here is my code: Template: <form action="" method="post"> {% csrf_token %} {{ formset.management_form }} {% for form in formset %} {{ form.as_p }} {% endfor %} <input type="submit" value="Submit"> </form> View: def addMembers(request, id, members): if request.user.is_authenticated(): members = int(members) MemberFormSet = formset_factory(MemberForm, extra = members) if request.method == 'POST': print 'post' formset = MemberFormSet(request.POST) if formset.is_valid(): cd = formset.cleaned_data for f in formset: first_name =

Django Formset.is_valid() failing for extra forms

我是研究僧i 提交于 2019-11-30 06:44:31
In my Django application application I have a formset that is created from a simple (not-model) form, with the extra=1 (to allow javasript to add more forms later on). class SomeForm(forms.Form): #some fields with required=False length = forms.IntegerField(required=False) # An example of one of the fields with choices i have A = 0 B = 1 C = 2 D = 3 choices = ((A, 'Aah'), (B, 'Baa'), (C, 'Caa'), (D, 'Daa')) # This is a required choice field pickme = forms.ChoiceField(choices=choices) SomeFormset = formset_factory(SomeForm, can_delete=True, extra=1) Now, when I create and try to validate it in