Ticket #5931: 5931.repr_for_model_fields.diff

File 5931.repr_for_model_fields.diff, 1.3 KB (added by Johannes Dollinger, 15 years ago)

added a test

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

     
    339339        "Returns the value of this field in the given model instance."
    340340        return getattr(obj, self.attname)
    341341
     342    def __repr__(self):
     343        return '<%s.%s %s>' % (self.__class__.__module__, self.__class__.__name__, getattr(self, "name", None))
     344   
    342345class AutoField(Field):
    343346    empty_strings_allowed = False
    344347    def __init__(self, *args, **kwargs):
  • tests/regressiontests/model_fields/tests.py

     
    144144        bs = BigS.objects.create(s = 'slug'*50)
    145145        bs = BigS.objects.get(pk=bs.pk)
    146146        self.assertEqual(bs.s, 'slug'*50)
     147
     148class FieldReprTests(django.test.TestCase):
     149    def test_field_repr(self):
     150        f = Foo._meta.get_field('a')
     151        self.assertEqual(repr(f), '<django.db.models.fields.CharField a>')
     152        f = Bar._meta.get_field('a')
     153        self.assertEqual(repr(f), '<django.db.models.fields.related.ForeignKey a>')
     154
Back to Top