I found the issue (or non issue, whatever you like ;)) get_test_char_display() calls the field's choices with a string (of course it is a CharField), which results in the following call (stripped down talen from django/db/models/base.py: dict(choices).get(value,value) Now accesing it with a string as value would raise a KeyError so the value saved in the CharField is returned, which is a string containing an int.
The remaining question now is whether this should get documented somehow (eg match the type of the field...) or not. Of course it doesn't make sense to use integers and then store them in the db, but this question popped up a few times in irc... On Dec 29, 10:32 pm, Florian Apolloner <[EMAIL PROTECTED]> wrote: > > Error is in the way you use it. Please write full model and usage > > example. > > As you wish :) > > blubb/models.py: > > from django.db import models > > # Create your models here. > MY_CHOICES = ( > (1, '11'), > (2, '12') > ) > class TestModel(models.Model): > test_blubb = models.IntegerField(choices=MY_CHOICES) > test_char = models.CharField(choices=MY_CHOICES, max_length=100) > > Testcode > ./manage.py shell > Python 2.4.4 (#2, Aug 16 2007, 02:03:40) > [GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole)>>> from blubb.models import * > >>> a = TestModel.objects.get(pk=1) > >>> a.get_test_blubb_display() > u'11' > >>> a.get_test_char_display() > > u'2' > > Where the last one should be u'12' instead of u'2'. The problem seems > to be with CharField. If I use str for all the choices it does work... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---