Hi all.
I'm developing a model with a 'self' FK (much like categories with
multiple levels), and all works good, but when i try to get the parent
name in __str__ admin modify give me a 404 "subdivision object with
primary key 'the_code_here' does not exist", but if i remove the
reference to parent, all works good. The most strange is that in admin
list view and in shell all is ok and give me the desired output.
Is it a bug in admin view or i'm doing something bad?
Thanks.
PD: Here is my code:
class Subdivision(models.Model):
"""
Country subdivision in ISO 3166-2 subdivision code
"""
code = models.CharField(_('Code'), maxlength=10, primary_key=True)
name = models.CharField(_('Name'), maxlength=100, core=True)
stype = models.CharField(_('Type'), maxlength=3,
choices=COUNTRY_SUBDIVISION_TYPE)
country = models.ForeignKey(Country, verbose_name=_('Country'))
island = models.ForeignKey(Island, verbose_name=_('Island'),
blank=True, null=True)
parent = models.ForeignKey('self', related_name="children",
verbose_name=_('Parent Subdivision'),
blank=True, null=True)
lat = models.FloatField(_('Latitude'),
max_digits=9, decimal_places=6, blank=True, null=True)
lon = models.FloatField(_('Longitude'),
max_digits=9, decimal_places=6, blank=True, null=True)
def __str__(self):
if self.parent:
return ('%s (%s of %s, %s)') % (self.name,
self.get_stype_display(),
self.parent.name,
self.country)
else:
return ('%s (%s of %s)') % (self.name,
self.get_stype_display(),
self.country)
__str__.short_description = _("Description")
class Admin:
list_display = ('code','name','island','__str__')
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---