Ticket #12546: django-len-serialization.diff

File django-len-serialization.diff, 2.1 KB (added by Alex Gaynor, 15 years ago)
  • django/db/models/fields/__init__.py

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index e9e3f4a..05f16db 100644
    a b class Field(object):  
    404404        return first_choice + list(self.flatchoices)
    405405
    406406    def _get_val_from_obj(self, obj):
    407         if obj:
     407        if obj is not None:
    408408            return getattr(obj, self.attname)
    409409        else:
    410410            return self.get_default()
  • tests/regressiontests/serializers_regress/models.py

    diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py
    index ccd8503..087551e 100644
    a b class InheritBaseModel(BaseModel):  
    258258class ExplicitInheritBaseModel(BaseModel):
    259259    parent = models.OneToOneField(BaseModel)
    260260    child_data = models.IntegerField()
     261
     262class LengthModel(models.Model):
     263    data = models.IntegerField()
     264   
     265    def __len__(self):
     266        return self.data
  • tests/regressiontests/serializers_regress/tests.py

    diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
    index 11b53a5..84e90ff 100644
    a b forward, backwards and self references.  
    88"""
    99
    1010
    11 import unittest, datetime
     11import datetime
     12import decimal
     13import unittest
    1214from cStringIO import StringIO
    1315
    1416from django.utils.functional import curry
    from django.core import management  
    1820from django.conf import settings
    1921
    2022from models import *
    21 try:
    22     import decimal
    23 except ImportError:
    24     from django.utils import _decimal as decimal
    2523
    2624# A set of functions that can be used to recreate
    2725# test data objects of various kinds.
    The end."""),  
    326324    (data_obj, 1001, BigIntegerData, -9223372036854775808),
    327325    (data_obj, 1002, BigIntegerData, 0),
    328326    (data_obj, 1003, BigIntegerData, None),
     327    (data_obj, 1004, LengthModel, 0),
     328    (data_obj, 1005, LengthModel, 1),
    329329]
    330330
    331331# Because Oracle treats the empty string as NULL, Oracle is expected to fail
Back to Top