Ticket #10728: 0001-Create-a-test-highlighting-a-SubfieldBase-issue.patch

File 0001-Create-a-test-highlighting-a-SubfieldBase-issue.patch, 1.6 KB (added by Gabriel, 15 years ago)

test

  • tests/modeltests/field_subclassing/models.py

    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):  
    5353            return []
    5454        raise FieldError('Invalid lookup type: %r' % lookup_type)
    5555
     56class OtherField(SmallField):
     57    """
     58    Check the SubfieldBase metaclass works with inheritance.
     59    """
     60
     61    pass
     62
    5663class MyModel(models.Model):
    5764    name = models.CharField(max_length=10)
    5865    data = SmallField('small field')
     66    other_data = OtherField(default='example')
    5967
    6068    def __unicode__(self):
    6169        return force_unicode(self.name)
    FieldError: Invalid lookup type: 'lt'  
    97105# Serialization works, too.
    98106>>> stream = serializers.serialize("json", MyModel.objects.all())
    99107>>> 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"}}]'
    101109>>> obj = list(serializers.deserialize("json", stream))[0]
    102110>>> obj.object == m
    103111True
Back to Top