models.py 777 B

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. Tests for field subclassing.
  3. """
  4. from django.db import models
  5. from django.utils.encoding import force_text, python_2_unicode_compatible
  6. from .fields import JSONField, Small, SmallerField, SmallField
  7. @python_2_unicode_compatible
  8. class MyModel(models.Model):
  9. name = models.CharField(max_length=10)
  10. data = SmallField('small field')
  11. def __str__(self):
  12. return force_text(self.name)
  13. class OtherModel(models.Model):
  14. data = SmallerField()
  15. class ChoicesModel(models.Model):
  16. SMALL_AB = Small('a', 'b')
  17. SMALL_CD = Small('c', 'd')
  18. SMALL_CHOICES = (
  19. (SMALL_AB, str(SMALL_AB)),
  20. (SMALL_CD, str(SMALL_CD)),
  21. )
  22. data = SmallField('small field', choices=SMALL_CHOICES)
  23. class DataModel(models.Model):
  24. data = JSONField()