I have this structure:
class Album(models.Model):
caption = models.CharField(max_length=500)
def get_album_type(self):
if self.a_set.count() > 0: return 'a'
if self.b_set.count() > 0: return 'b'
def _get_a(self):
return self.a_set.all()[0]
def _get_b(self):
return self.b_set.all()[0]
a = property(_get_a)
b = property(_get_b)
class A(models.Model):
album = models.ForeignKey('album.Album', null=True)
class B(models.Model):
album = models.ForeignKey('album.Album', null=True)
I need to know what is the type of the album and access the related
object, currently using the solution above.
In a template with many albums I'm running a lot of queries, is there
a better way of doing this (a least for the get_album_type function)?
regards
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.