mirror of
https://github.com/django/django.git
synced 2025-07-07 11:19:12 +00:00
[soc2009/model-validation] Added tests using model inheritance
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10880 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
eae2b9c149
commit
4449ff33a0
@ -74,7 +74,7 @@ class ImprovedArticleWithParentLink(models.Model):
|
|||||||
article = models.OneToOneField(Article, parent_link=True)
|
article = models.OneToOneField(Article, parent_link=True)
|
||||||
|
|
||||||
class BetterWriter(Writer):
|
class BetterWriter(Writer):
|
||||||
pass
|
score = models.IntegerField()
|
||||||
|
|
||||||
class WriterProfile(models.Model):
|
class WriterProfile(models.Model):
|
||||||
writer = models.OneToOneField(Writer, primary_key=True)
|
writer = models.OneToOneField(Writer, primary_key=True)
|
||||||
@ -969,10 +969,20 @@ ValidationError: [u'Select a valid choice. 4 is not one of the available choices
|
|||||||
>>> ImprovedArticleWithParentLinkForm.base_fields.keys()
|
>>> ImprovedArticleWithParentLinkForm.base_fields.keys()
|
||||||
[]
|
[]
|
||||||
|
|
||||||
>>> bw = BetterWriter(name=u'Joe Better')
|
>>> bw = BetterWriter(name=u'Joe Better', score=10)
|
||||||
>>> bw.save()
|
>>> bw.save()
|
||||||
>>> sorted(model_to_dict(bw).keys())
|
>>> sorted(model_to_dict(bw).keys())
|
||||||
['id', 'name', 'writer_ptr']
|
['id', 'name', 'score', 'writer_ptr']
|
||||||
|
|
||||||
|
>>> class BetterWriterForm(ModelForm):
|
||||||
|
... class Meta:
|
||||||
|
... model = BetterWriter
|
||||||
|
>>> form = BetterWriterForm({'name': 'Some Name', 'score': 12})
|
||||||
|
>>> form.is_valid()
|
||||||
|
True
|
||||||
|
>>> bw2 = form.save()
|
||||||
|
>>> bw2.delete()
|
||||||
|
|
||||||
|
|
||||||
>>> class WriterProfileForm(ModelForm):
|
>>> class WriterProfileForm(ModelForm):
|
||||||
... class Meta:
|
... class Meta:
|
||||||
@ -1390,6 +1400,8 @@ False
|
|||||||
>>> form = PriceForm({'price': '6.00'})
|
>>> form = PriceForm({'price': '6.00'})
|
||||||
>>> form.is_valid()
|
>>> form.is_valid()
|
||||||
False
|
False
|
||||||
|
>>> form.errors
|
||||||
|
{'quantity': [u'This field cannot be null.']}
|
||||||
|
|
||||||
# Unique & unique together with null values
|
# Unique & unique together with null values
|
||||||
>>> class BookForm(ModelForm):
|
>>> class BookForm(ModelForm):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user