Ticket #10284: models.py

File models.py, 881 bytes (added by Wedg, 5 years ago)

Regression test for issue.

Line 
1from django.db import models
2
3class MyModel( models.Model ):
4    """
5    Test ModelFormSet.save(commit=False) delete behavior
6
7    >>> from apps.modelformset_regress.models import MyModel
8    >>> MyModel(name='Foobar').save()
9    >>> MyModel.objects.all()
10    [<MyModel: Foobar>]
11    >>> from django.forms.models import modelformset_factory
12    >>> MyFormSet = modelformset_factory(MyModel, can_delete=True)
13    >>> formset = MyFormSet({
14    ... 'form-TOTAL_FORMS':'2',
15    ... 'form-INITIAL_FORMS':'1',
16    ... 'form-MAX_NUM_FORMS':'',
17    ... 'form-0-name':'Foobar',
18    ... 'form-0-DELETE':'1',
19    ... 'form-0-id':'1',
20    ... })
21    >>> formset.is_valid()
22    True
23    >>> formset.save(commit=False)
24    []
25    >>> MyModel.objects.all()
26    [<MyModel: Foobar>]
27    """
28    name = models.CharField(max_length=20)
29
30    def __unicode__( self ):
31        return u'%s' % self.name
32
Back to Top