2007-11-05 21:59:42 +08:00
|
|
|
"""
|
|
|
|
Tests for field subclassing.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
2012-07-21 16:00:10 +08:00
|
|
|
from django.utils.encoding import force_text
|
2007-11-05 21:59:42 +08:00
|
|
|
|
2014-04-12 11:58:56 +08:00
|
|
|
from .fields import Small, SmallField, SmallerField, JSONField
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2007-11-05 21:59:42 +08:00
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2007-11-05 21:59:42 +08:00
|
|
|
class MyModel(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
data = SmallField('small field')
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-07-21 16:00:10 +08:00
|
|
|
return force_text(self.name)
|
2007-11-05 21:59:42 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2010-11-03 02:40:53 +08:00
|
|
|
class OtherModel(models.Model):
|
|
|
|
data = SmallerField()
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2014-04-12 11:58:56 +08: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-25 03:06:59 +08:00
|
|
|
class DataModel(models.Model):
|
|
|
|
data = JSONField()
|