|
1 # -*- coding: utf-8 -*- |
|
2 import datetime |
|
3 import tempfile |
|
4 |
|
5 from django.db import models |
|
6 from django.core.files.storage import FileSystemStorage |
|
7 |
|
8 |
|
9 temp_storage_location = tempfile.mkdtemp() |
|
10 temp_storage = FileSystemStorage(location=temp_storage_location) |
|
11 |
|
12 |
|
13 class BoundaryModel(models.Model): |
|
14 positive_integer = models.PositiveIntegerField(null=True, blank=True) |
|
15 |
|
16 |
|
17 callable_default_value = 0 |
|
18 def callable_default(): |
|
19 global callable_default_value |
|
20 callable_default_value = callable_default_value + 1 |
|
21 return callable_default_value |
|
22 |
|
23 |
|
24 class 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 |
|
31 class ChoiceModel(models.Model): |
|
32 """For ModelChoiceField and ModelMultipleChoiceField tests.""" |
|
33 name = models.CharField(max_length=10) |
|
34 |
|
35 |
|
36 class 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 |
|
48 class 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 |
|
62 class FileModel(models.Model): |
|
63 file = models.FileField(storage=temp_storage, upload_to='tests') |
|
64 |
|
65 |
|
66 class Group(models.Model): |
|
67 name = models.CharField(max_length=10) |
|
68 |
|
69 def __unicode__(self): |
|
70 return u'%s' % self.name |
|
71 |
|
72 |
|
73 class Cheese(models.Model): |
|
74 name = models.CharField(max_length=100) |