2008-07-20 02:47:59 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-10-20 21:01:40 +08:00
|
|
|
import datetime
|
2010-10-12 11:33:19 +08:00
|
|
|
import tempfile
|
2007-10-20 21:01:40 +08:00
|
|
|
|
2010-10-12 11:33:19 +08:00
|
|
|
from django.db import models
|
2009-01-17 05:31:58 +08:00
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
|
|
|
|
|
temp_storage_location = tempfile.mkdtemp()
|
|
|
|
temp_storage = FileSystemStorage(location=temp_storage_location)
|
2007-09-15 10:37:07 +08:00
|
|
|
|
2007-10-20 21:01:40 +08:00
|
|
|
class BoundaryModel(models.Model):
|
2007-09-15 10:37:07 +08:00
|
|
|
positive_integer = models.PositiveIntegerField(null=True, blank=True)
|
2007-10-20 21:01:40 +08:00
|
|
|
|
2010-03-08 23:03:30 +08:00
|
|
|
callable_default_value = 0
|
|
|
|
def callable_default():
|
|
|
|
global callable_default_value
|
|
|
|
callable_default_value = callable_default_value + 1
|
|
|
|
return callable_default_value
|
|
|
|
|
2007-10-20 21:01:40 +08:00
|
|
|
class Defaults(models.Model):
|
2009-05-08 02:06:22 +08:00
|
|
|
name = models.CharField(max_length=255, default='class default value')
|
2007-10-23 06:04:00 +08:00
|
|
|
def_date = models.DateField(default = datetime.date(1980, 1, 1))
|
2007-10-20 21:01:40 +08:00
|
|
|
value = models.IntegerField(default=42)
|
2010-03-08 23:03:30 +08:00
|
|
|
callable_default = models.IntegerField(default=callable_default)
|
2007-10-20 21:01:40 +08:00
|
|
|
|
2007-11-19 04:25:23 +08:00
|
|
|
class ChoiceModel(models.Model):
|
|
|
|
"""For ModelChoiceField and ModelMultipleChoiceField tests."""
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2009-05-10 15:44:27 +08:00
|
|
|
class ChoiceOptionModel(models.Model):
|
|
|
|
"""Destination for ChoiceFieldModel's ForeignKey.
|
|
|
|
Can't reuse ChoiceModel because error_message tests require that it have no instances."""
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2010-08-14 20:05:41 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'ChoiceOption %d' % self.pk
|
|
|
|
|
2009-05-10 15:44:27 +08:00
|
|
|
class ChoiceFieldModel(models.Model):
|
|
|
|
"""Model with ForeignKey to another model, for testing ModelForm
|
|
|
|
generation with ModelChoiceField."""
|
|
|
|
choice = models.ForeignKey(ChoiceOptionModel, blank=False,
|
2010-08-14 20:05:41 +08:00
|
|
|
default=lambda: ChoiceOptionModel.objects.get(name='default'))
|
|
|
|
choice_int = models.ForeignKey(ChoiceOptionModel, blank=False, related_name='choice_int',
|
|
|
|
default=lambda: 1)
|
|
|
|
|
|
|
|
multi_choice = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice',
|
|
|
|
default=lambda: ChoiceOptionModel.objects.filter(name='default'))
|
|
|
|
multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int',
|
|
|
|
default=lambda: [1])
|
|
|
|
|
2008-07-20 02:47:59 +08:00
|
|
|
class FileModel(models.Model):
|
2009-01-17 05:31:58 +08:00
|
|
|
file = models.FileField(storage=temp_storage, upload_to='tests')
|
2008-07-20 02:47:59 +08:00
|
|
|
|
2010-01-12 22:58:24 +08:00
|
|
|
class Group(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s' % self.name
|