PageRenderTime 41ms CodeModel.GetById 36ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/models.py

https://code.google.com/p/mango-py/
Python | 74 lines | 59 code | 13 blank | 2 comment | 0 complexity | 91eee1d134ee30b36296ebf021876435 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2import datetime
 3import tempfile
 4
 5from django.db import models
 6from django.core.files.storage import FileSystemStorage
 7
 8
 9temp_storage_location = tempfile.mkdtemp()
10temp_storage = FileSystemStorage(location=temp_storage_location)
11
12
13class BoundaryModel(models.Model):
14    positive_integer = models.PositiveIntegerField(null=True, blank=True)
15
16
17callable_default_value = 0
18def callable_default():
19    global callable_default_value
20    callable_default_value = callable_default_value + 1
21    return callable_default_value
22
23
24class Defaults(models.Model):
25    name = models.CharField(max_length=255, default='class default value')
26    def_date = models.DateField(default = datetime.date(1980, 1, 1))
27    value = models.IntegerField(default=42)
28    callable_default = models.IntegerField(default=callable_default)
29
30
31class ChoiceModel(models.Model):
32    """For ModelChoiceField and ModelMultipleChoiceField tests."""
33    name = models.CharField(max_length=10)
34
35
36class ChoiceOptionModel(models.Model):
37    """Destination for ChoiceFieldModel's ForeignKey.
38    Can't reuse ChoiceModel because error_message tests require that it have no instances."""
39    name = models.CharField(max_length=10)
40
41    class Meta:
42        ordering = ('name',)
43
44    def __unicode__(self):
45        return u'ChoiceOption %d' % self.pk
46
47
48class ChoiceFieldModel(models.Model):
49    """Model with ForeignKey to another model, for testing ModelForm
50    generation with ModelChoiceField."""
51    choice = models.ForeignKey(ChoiceOptionModel, blank=False,
52                               default=lambda: ChoiceOptionModel.objects.get(name='default'))
53    choice_int = models.ForeignKey(ChoiceOptionModel, blank=False, related_name='choice_int',
54                                   default=lambda: 1)
55
56    multi_choice = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice',
57                                          default=lambda: ChoiceOptionModel.objects.filter(name='default'))
58    multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int',
59                                              default=lambda: [1])
60
61
62class FileModel(models.Model):
63    file = models.FileField(storage=temp_storage, upload_to='tests')
64
65
66class Group(models.Model):
67    name = models.CharField(max_length=10)
68
69    def __unicode__(self):
70        return u'%s' % self.name
71
72
73class Cheese(models.Model):
74   name = models.CharField(max_length=100)