Monday, November 12, 2012

A problem about get_absolute_url()

Hi all,

I have 4 classes and i want to build a get_absolute_url() for a class,
querying other 3 classes. But i get "list index out of range" error
for the FILTER row. Any ideas?

class Aaa( models.Model ):
...
...

class City( models.Model ):
...
...

class Bbb( models.Model ):
aaa = models.ForeignKey( Aaa )
city = models.ForeignKey( City )
...
...

class Ccc( models.Model ):
aaa = models.ForeignKey( Aaa )
...
...

def get_absolute_url(self):

bbbs = Bbb.objects.filter( aaa = self.aaa )

city = City.objects.get( id = bbbs[0].city.id )

return "/" + city.name + "/" + str(self.id)

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate