I'm looking for an efficient way of combining two different models into
a single list for a folk song and lyrics sharing app. Many folk songs
are known by a variety of names, so to reflect this I created these two
models (leaving out a bunch of fields/definitions)
class Song(models.Model):
title = models.CharField(maxlength=30)
slug = models.SlugField(prepopulate_from=("title", ))
[...]
def get_absolute_url(self):
return "/songs/%s" % self.slug
class Alias(models.Model):
title = models.CharField(maxlength=30, core=True)
song = models.ForeignKey(Song, edit_inline=models.TABULAR)
def get_absolute_url(self):
return self.song.get_absolute_url ()
The main thing the aliases are used for is putting entries on the songs
lists on index and category pages. I'm doing this in my views:
def index(request):
titles = list(Alias.objects.all()) + list( Song.objects.all())
titles.sort(lambda x, y: cmp(x.title, y.title)
return render_to_response('songs/index.html', {'titles': titles})
This gives me lists of objects with the correct attributes and methods
which is great, and when I need to filter the results (for example, for
category views) I can easily do that by replacing .all() with .filter()
or whatever else. The problem with this solution is that I need to pull
the entire set of results into a list, and (if the site catches on),
that's bad memory use and potentially slow. I wish it were possible to
create an iterable object like a queryset that could be assigned two
models to do this more efficiently. If anyone has advice about any more
efficient way to get this done, I'd appreciate it.
Thanks,
Benj
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---