I can't seem to figure out what is causing this: According to the following 2 models
and the 'python manage.py shell' session shown after them, I am getting 2L as a
return value from a certain call when I would expect u'redhat 5.6' or similar.
If anyone has any ideas, please let me know. I am very stumped at this point.
I include (and query) "Status" just to show normal/expected output from a very
similar query for a field value.
class Status(models.Model):
name = models.CharField('Status',
max_length=30,
primary_key=True)
def __unicode__(self):
return self.name
class Distro(models.Model):
# don't make name the primary key, because then it has to be
# unique and we want to allow multiple items with the same
# 'name', like ubuntu 10.10 and ubuntu 11.04
name = models.CharField('Distro Brand',
help_text='redhat, ubuntu, etc',
max_length=30)
version = models.CharField('Distro Version',
help_text='Not kernel version',
max_length=10)
def __unicode__(self):
return u"%s %s" % (self.name, self.version)
=============================================================
>>> from hostdb.models import Device, Interface
>>> hostname = 'beijing.mitre.org'
>>> dev = Interface.objects.get(fqdn=hostname).device
>>> dev.status
<Status: Online>
>>> f = dev._meta.get_field('status')
>>> f.value_from_object(dev)
u'Online'
>>> # Super -- this is exactly what I would expect. Now trouble
>>> dev.distro
<Distro: redhat 5.6>
>>> print dev.distro
redhat 5.6
>>> f = dev._meta.get_field('distro')
>>> f.value_from_object(dev)
2L
>>> # what the hell?
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/BEubx9rDBd0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment