Ticket #12568: subfieldbase-20130917.diff

File subfieldbase-20130917.diff, 1.6 KB (added by c v t, 11 years ago)

Rebased against git master (5be56d0)

  • django/db/models/fields/subclassing.py

    diff --git a/django/db/models/fields/subclassing.py b/django/db/models/fields/subclassing.py
    index 591adb7..43c3449 100644
    a b class Creator(object):  
    3030
    3131    def __get__(self, obj, type=None):
    3232        if obj is None:
    33             raise AttributeError('Can only be accessed via an instance.')
     33             return self
    3434        return obj.__dict__[self.field.name]
    3535
    3636    def __set__(self, obj, value):
  • tests/field_subclassing/tests.py

    diff --git a/tests/field_subclassing/tests.py b/tests/field_subclassing/tests.py
    index d3b4d9e..176d9bc 100644
    a b  
    11from __future__ import unicode_literals
    22
     3import inspect
     4
    35from django.core import serializers
    46from django.test import TestCase
    57
    class CustomField(TestCase):  
    9092        o = OtherModel.objects.get()
    9193        self.assertEqual(o.data.first, "a")
    9294        self.assertEqual(o.data.second, "b")
     95
     96    def test_subfieldbase_plays_nice_with_module_inspect(self):
     97        """
     98        Custom fields should play nice with python standard module inspect.
     99
     100        http://users.rcn.com/python/download/Descriptor.htm#properties
     101        """
     102        # even when looking for totally different properties, SubfieldBase it's
     103        # non property like behaviour makes inspect crash.
     104        strings = inspect.getmembers(MyModel, lambda x: type(x) is str)
     105        known_strings = [('__module__', 'field_subclassing.models')]
     106
     107        self.assertEqual(strings, known_strings)
     108
     109        # should also not raise an exception
     110        inspect.getmembers(MyModel)
Back to Top