mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #10728 -- corrected subclassing of Fields who use the SubfieldBase metaclass. Thanks to G2P and George Sakkis for their work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14443 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
352deb0915
commit
222c732616
4 changed files with 18 additions and 5 deletions
|
@ -52,6 +52,9 @@ class SmallField(models.Field):
|
|||
return []
|
||||
raise TypeError('Invalid lookup type: %r' % lookup_type)
|
||||
|
||||
class SmallerField(SmallField):
|
||||
pass
|
||||
|
||||
|
||||
class JSONField(models.TextField):
|
||||
__metaclass__ = models.SubfieldBase
|
||||
|
|
|
@ -5,7 +5,7 @@ Tests for field subclassing.
|
|||
from django.db import models
|
||||
from django.utils.encoding import force_unicode
|
||||
|
||||
from fields import Small, SmallField, JSONField
|
||||
from fields import Small, SmallField, SmallerField, JSONField
|
||||
|
||||
|
||||
class MyModel(models.Model):
|
||||
|
@ -15,5 +15,8 @@ class MyModel(models.Model):
|
|||
def __unicode__(self):
|
||||
return force_unicode(self.name)
|
||||
|
||||
class OtherModel(models.Model):
|
||||
data = SmallerField()
|
||||
|
||||
class DataModel(models.Model):
|
||||
data = JSONField()
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.core import serializers
|
|||
from django.test import TestCase
|
||||
|
||||
from fields import Small
|
||||
from models import DataModel, MyModel
|
||||
from models import DataModel, MyModel, OtherModel
|
||||
|
||||
|
||||
class CustomField(TestCase):
|
||||
|
@ -73,3 +73,9 @@ class CustomField(TestCase):
|
|||
],
|
||||
lambda m: str(m.data)
|
||||
)
|
||||
|
||||
def test_field_subclassing(self):
|
||||
o = OtherModel.objects.create(data=Small("a", "b"))
|
||||
o = OtherModel.objects.get()
|
||||
self.assertEqual(o.data.first, "a")
|
||||
self.assertEqual(o.data.second, "b")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue