From e7aef916ca5ac08264ff2fe8619f4cf2287453d7 Mon Sep 17 00:00:00 2001
From: Gabriel <g2p.code@gmail.com>
Date: Sat, 4 Apr 2009 02:22:01 +0200
Subject: [PATCH 1/2] Create a test highlighting a SubfieldBase issue.
The simple test fails. Classes using SubfieldBase can't be extended.
---
tests/modeltests/field_subclassing/models.py | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/tests/modeltests/field_subclassing/models.py b/tests/modeltests/field_subclassing/models.py
index c776146..b317e1d 100644
a
|
b
|
class SmallField(models.Field):
|
53 | 53 | return [] |
54 | 54 | raise FieldError('Invalid lookup type: %r' % lookup_type) |
55 | 55 | |
| 56 | class OtherField(SmallField): |
| 57 | """ |
| 58 | Check the SubfieldBase metaclass works with inheritance. |
| 59 | """ |
| 60 | |
| 61 | pass |
| 62 | |
56 | 63 | class MyModel(models.Model): |
57 | 64 | name = models.CharField(max_length=10) |
58 | 65 | data = SmallField('small field') |
| 66 | other_data = OtherField(default='example') |
59 | 67 | |
60 | 68 | def __unicode__(self): |
61 | 69 | return force_unicode(self.name) |
… |
… |
FieldError: Invalid lookup type: 'lt'
|
97 | 105 | # Serialization works, too. |
98 | 106 | >>> stream = serializers.serialize("json", MyModel.objects.all()) |
99 | 107 | >>> stream |
100 | | '[{"pk": 1, "model": "field_subclassing.mymodel", "fields": {"data": "12", "name": "m"}}]' |
| 108 | '[{"pk": 1, "model": "field_subclassing.mymodel", "fields": {"data": "12", "name": "m", "other_data": "ex"}}]' |
101 | 109 | >>> obj = list(serializers.deserialize("json", stream))[0] |
102 | 110 | >>> obj.object == m |
103 | 111 | True |