mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #20228 - Documented unique_for_date and exclude behavior.
Thanks Deepak Thukral for the patch.
This commit is contained in:
@@ -24,7 +24,7 @@ from .models import (Article, ArticleStatus, BetterAuthor, BigInt,
|
||||
DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
|
||||
ImprovedArticleWithParentLink, Inventory, Post, Price,
|
||||
Product, TextFile, AuthorProfile, Colour, ColourfulItem,
|
||||
ArticleStatusNote, test_images)
|
||||
ArticleStatusNote, DateTimePost, test_images)
|
||||
|
||||
if test_images:
|
||||
from .models import ImageFile, OptionalImageFile
|
||||
@@ -76,6 +76,12 @@ class PostForm(forms.ModelForm):
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class DateTimePostForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = DateTimePost
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class DerivedPostForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = DerivedPost
|
||||
@@ -682,6 +688,23 @@ class UniqueTest(TestCase):
|
||||
self.assertEqual(len(form.errors), 1)
|
||||
self.assertEqual(form.errors['posted'], ['This field is required.'])
|
||||
|
||||
def test_unique_for_date_in_exclude(self):
|
||||
"""If the date for unique_for_* constraints is excluded from the
|
||||
ModelForm (in this case 'posted' has editable=False, then the
|
||||
constraint should be ignored."""
|
||||
p = DateTimePost.objects.create(title="Django 1.0 is released",
|
||||
slug="Django 1.0", subtitle="Finally",
|
||||
posted=datetime.datetime(2008, 9, 3, 10, 10, 1))
|
||||
# 'title' has unique_for_date='posted'
|
||||
form = DateTimePostForm({'title': "Django 1.0 is released", 'posted': '2008-09-03'})
|
||||
self.assertTrue(form.is_valid())
|
||||
# 'slug' has unique_for_year='posted'
|
||||
form = DateTimePostForm({'slug': "Django 1.0", 'posted': '2008-01-01'})
|
||||
self.assertTrue(form.is_valid())
|
||||
# 'subtitle' has unique_for_month='posted'
|
||||
form = DateTimePostForm({'subtitle': "Finally", 'posted': '2008-09-30'})
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
def test_inherited_unique_for_date(self):
|
||||
p = Post.objects.create(title="Django 1.0 is released",
|
||||
slug="Django 1.0", subtitle="Finally", posted=datetime.date(2008, 9, 3))
|
||||
|
||||
Reference in New Issue
Block a user