Changes between Initial Version and Version 2 of Ticket #28799


Ignore:
Timestamp:
Nov 16, 2017, 4:41:12 AM (7 years ago)
Author:
Sergey Fedoseev
Comment:

I updated test to make it closer to my situation: min_num=2, validate_min=True, the first form is unchanged, the second one is filled. In this case objects are created.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28799 – Description

    initial v2  
    33{{{
    44from django.db import models
     5from django.forms.models import modelformset_factory
     6from django.test import TestCase
    57
    6 from django.test import TestCase
    7 from django.forms.models import modelformset_factory
    8 
    9 class Price(models.Model):
    10     quantity = models.PositiveIntegerField()
     8class Author(models.Model):
     9    name = models.CharField(max_length=100)
    1110
    1211class ModelFormsetTest(TestCase):
     
    1514            'form-TOTAL_FORMS': '2',
    1615            'form-INITIAL_FORMS': '0',
    17             'form-0-quantity': '1',
     16            'form-0-name': 'a',
     17            'form-1-name': 'b',
    1818        }
    1919
    20         FormSet = modelformset_factory(Price, fields=('quantity',), min_num=1, validate_min=True)
    21         formset = FormSet(data, initial=[{'quantity': 1}])
     20        FormSet = modelformset_factory(Author, min_num=2, exclude=(), validate_min=True)
     21        formset = FormSet(data=data, queryset=Author.objects.none(), initial=[{'name': 'a'}])
    2222        self.assertTrue(formset.is_valid())
     23        self.assertTrue(len(formset.save()), 2)
    2324}}}
    2425
Back to Top