2008-07-19 18:47:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2011-11-13 19:05:02 +00:00
|
|
|
import os
|
2007-10-20 13:01:40 +00:00
|
|
|
import datetime
|
2010-10-12 03:33:19 +00:00
|
|
|
import tempfile
|
2007-10-20 13:01:40 +00:00
|
|
|
|
2009-01-16 21:31:58 +00:00
|
|
|
from django.core.files.storage import FileSystemStorage
|
2011-10-13 18:51:33 +00:00
|
|
|
from django.db import models
|
2009-01-16 21:31:58 +00:00
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2011-11-13 19:05:02 +00:00
|
|
|
temp_storage_location = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
|
2009-01-16 21:31:58 +00:00
|
|
|
temp_storage = FileSystemStorage(location=temp_storage_location)
|
2007-09-15 02:37:07 +00:00
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2007-10-20 13:01:40 +00:00
|
|
|
class BoundaryModel(models.Model):
|
2007-09-15 02:37:07 +00:00
|
|
|
positive_integer = models.PositiveIntegerField(null=True, blank=True)
|
2007-10-20 13:01:40 +00:00
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2010-03-08 15:03:30 +00:00
|
|
|
callable_default_value = 0
|
|
|
|
def callable_default():
|
|
|
|
global callable_default_value
|
|
|
|
callable_default_value = callable_default_value + 1
|
|
|
|
return callable_default_value
|
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2007-10-20 13:01:40 +00:00
|
|
|
class Defaults(models.Model):
|
2009-05-07 18:06:22 +00:00
|
|
|
name = models.CharField(max_length=255, default='class default value')
|
2007-10-22 22:04:00 +00:00
|
|
|
def_date = models.DateField(default = datetime.date(1980, 1, 1))
|
2007-10-20 13:01:40 +00:00
|
|
|
value = models.IntegerField(default=42)
|
2010-03-08 15:03:30 +00:00
|
|
|
callable_default = models.IntegerField(default=callable_default)
|
2007-10-20 13:01:40 +00:00
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2007-11-18 20:25:23 +00:00
|
|
|
class ChoiceModel(models.Model):
|
|
|
|
"""For ModelChoiceField and ModelMultipleChoiceField tests."""
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2009-05-10 07:44:27 +00: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 12:05:41 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return 'ChoiceOption %d' % self.pk
|
2010-08-14 12:05:41 +00:00
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2009-05-10 07:44:27 +00: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 12:05:41 +00: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])
|
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2008-07-19 18:47:59 +00:00
|
|
|
class FileModel(models.Model):
|
2009-01-16 21:31:58 +00:00
|
|
|
file = models.FileField(storage=temp_storage, upload_to='tests')
|
2008-07-19 18:47:59 +00:00
|
|
|
|
2010-11-18 22:43:46 +00:00
|
|
|
|
2010-01-12 14:58:24 +00:00
|
|
|
class Group(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return '%s' % self.name
|
2010-11-18 22:43:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Cheese(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|