2007-11-05 13:59:42 +00:00
|
|
|
"""
|
|
|
|
Tests for field subclassing.
|
|
|
|
"""
|
|
|
|
from django.db import models
|
2012-07-21 08:00:10 +00:00
|
|
|
from django.utils.encoding import force_text
|
2007-11-05 13:59:42 +00:00
|
|
|
|
2014-04-12 03:58:56 +00:00
|
|
|
from .fields import Small, SmallField, SmallerField, JSONField
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2007-11-05 13:59:42 +00:00
|
|
|
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2007-11-05 13:59:42 +00:00
|
|
|
class MyModel(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
data = SmallField('small field')
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2012-07-21 08:00:10 +00:00
|
|
|
return force_text(self.name)
|
2007-11-05 13:59:42 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-11-02 18:40:53 +00:00
|
|
|
class OtherModel(models.Model):
|
|
|
|
data = SmallerField()
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2014-04-12 03:58:56 +00:00
|
|
|
class ChoicesModel(models.Model):
|
|
|
|
SMALL_AB = Small('a', 'b')
|
|
|
|
SMALL_CD = Small('c', 'd')
|
|
|
|
SMALL_CHOICES = (
|
|
|
|
(SMALL_AB, str(SMALL_AB)),
|
|
|
|
(SMALL_CD, str(SMALL_CD)),
|
|
|
|
)
|
|
|
|
data = SmallField('small field', choices=SMALL_CHOICES)
|
|
|
|
|
|
|
|
|
2010-02-24 19:06:59 +00:00
|
|
|
class DataModel(models.Model):
|
|
|
|
data = JSONField()
|