PageRenderTime 44ms CodeModel.GetById 10ms 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
Possible License(s): BSD-3-Clause
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. import tempfile
  4. from django.db import models
  5. from django.core.files.storage import FileSystemStorage
  6. temp_storage_location = tempfile.mkdtemp()
  7. temp_storage = FileSystemStorage(location=temp_storage_location)
  8. class BoundaryModel(models.Model):
  9. positive_integer = models.PositiveIntegerField(null=True, blank=True)
  10. callable_default_value = 0
  11. def callable_default():
  12. global callable_default_value
  13. callable_default_value = callable_default_value + 1
  14. return callable_default_value
  15. class Defaults(models.Model):
  16. name = models.CharField(max_length=255, default='class default value')
  17. def_date = models.DateField(default = datetime.date(1980, 1, 1))
  18. value = models.IntegerField(default=42)
  19. callable_default = models.IntegerField(default=callable_default)
  20. class ChoiceModel(models.Model):
  21. """For ModelChoiceField and ModelMultipleChoiceField tests."""
  22. name = models.CharField(max_length=10)
  23. class ChoiceOptionModel(models.Model):
  24. """Destination for ChoiceFieldModel's ForeignKey.
  25. Can't reuse ChoiceModel because error_message tests require that it have no instances."""
  26. name = models.CharField(max_length=10)
  27. class Meta:
  28. ordering = ('name',)
  29. def __unicode__(self):
  30. return u'ChoiceOption %d' % self.pk
  31. class ChoiceFieldModel(models.Model):
  32. """Model with ForeignKey to another model, for testing ModelForm
  33. generation with ModelChoiceField."""
  34. choice = models.ForeignKey(ChoiceOptionModel, blank=False,
  35. default=lambda: ChoiceOptionModel.objects.get(name='default'))
  36. choice_int = models.ForeignKey(ChoiceOptionModel, blank=False, related_name='choice_int',
  37. default=lambda: 1)
  38. multi_choice = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice',
  39. default=lambda: ChoiceOptionModel.objects.filter(name='default'))
  40. multi_choice_int = models.ManyToManyField(ChoiceOptionModel, blank=False, related_name='multi_choice_int',
  41. default=lambda: [1])
  42. class FileModel(models.Model):
  43. file = models.FileField(storage=temp_storage, upload_to='tests')
  44. class Group(models.Model):
  45. name = models.CharField(max_length=10)
  46. def __unicode__(self):
  47. return u'%s' % self.name
  48. class Cheese(models.Model):
  49. name = models.CharField(max_length=100)