summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms/models.py
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2010-11-18 23:46:09 +0000
committerCarl Meyer <carl@oddbird.net>2010-11-18 23:46:09 +0000
commitd88cabd3da4bc82151ffaecc376c59478e191b20 (patch)
treefc1f5e47dc41671237bdf2053ad9621b7ed7cddc /tests/regressiontests/forms/models.py
parent395af9d5cf0f68130bfd75b9bdb2c20a8c6ef51a (diff)
[1.2.X] Fixed #14234 -- Re-validating a model instance added via ModelForm no longer throws spurious PK uniqueness errors. Thanks to David Reynolds and Jeremy Dunck.
Also moved Model._adding to Model._state.adding to reduce instance namespace footprint. Backport of r14612. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14615 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/models.py')
-rw-r--r--tests/regressiontests/forms/models.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py
index 0a0fea45ad..203980c11c 100644
--- a/tests/regressiontests/forms/models.py
+++ b/tests/regressiontests/forms/models.py
@@ -5,28 +5,34 @@ import tempfile
from django.db import models
from django.core.files.storage import FileSystemStorage
+
temp_storage_location = tempfile.mkdtemp()
temp_storage = FileSystemStorage(location=temp_storage_location)
+
class BoundaryModel(models.Model):
positive_integer = models.PositiveIntegerField(null=True, blank=True)
+
callable_default_value = 0
def callable_default():
global callable_default_value
callable_default_value = callable_default_value + 1
return callable_default_value
+
class Defaults(models.Model):
name = models.CharField(max_length=255, default='class default value')
def_date = models.DateField(default = datetime.date(1980, 1, 1))
value = models.IntegerField(default=42)
callable_default = models.IntegerField(default=callable_default)
+
class ChoiceModel(models.Model):
"""For ModelChoiceField and ModelMultipleChoiceField tests."""
name = models.CharField(max_length=10)
+
class ChoiceOptionModel(models.Model):
"""Destination for ChoiceFieldModel's ForeignKey.
Can't reuse ChoiceModel because error_message tests require that it have no instances."""
@@ -38,6 +44,7 @@ class ChoiceOptionModel(models.Model):
def __unicode__(self):
return u'ChoiceOption %d' % self.pk
+
class ChoiceFieldModel(models.Model):
"""Model with ForeignKey to another model, for testing ModelForm
generation with ModelChoiceField."""
@@ -51,11 +58,17 @@ class ChoiceFieldModel(models.Model):
multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int',
default=lambda: [1])
+
class FileModel(models.Model):
file = models.FileField(storage=temp_storage, upload_to='tests')
+
class Group(models.Model):
name = models.CharField(max_length=10)
def __unicode__(self):
return u'%s' % self.name
+
+
+class Cheese(models.Model):
+ name = models.CharField(max_length=100)