On Thu, 2006-08-10 at 22:09 +0930, Nick Lane wrote: > Hi everyone, > > I'm a relatively new user to Python and Django, and I'm impressed so far > - very nice! > > I have a question regarding the app I'm currently developing - a photo > album. Here is a rough copy of my models.py (trimmed for brevity): > > > class Photo(models.Model): > title = models.CharField(maxlength=50) > rating = models.PositiveIntegerField(default=0) > > class Album(models.Model): > title = models.CharField(maxlength=50) > pub_date = models.DateField() > > class AlbumPhoto(models.Model): > album = models.ForeignKey(Album, related_name='items') > photo = models.ForeignKey(Photo) > position = models.PositiveIntegerField() > > > I've used an intermediate class for the M-N relationship since I wanted > to store "position" to allow the user to order photos in a custom order. > > However, I also need to be able to retrieve photos from an album in > other orders, such as by the title or rating of the photo. I'm not sure > how to do this though, since order_by('photo__title') didn't seem to > work for me.
What filter construction are you trying to do here (you've just posted the order_by(...) part, but are you querying the Album model or the AlbumPhoto model)? Can you post the SQL we are constructing ("from django.db import connection" and then have a look at connection.queries[-1]['sql']). > It's quite possible (probable?) I'm going about this the wrong way but > am looking for any tips or suggestions about how this should be > implemented the "right" way in Django. This is a reasonably normal way to have a join table with properties. There have been other examples of people on this mailing list using it (can't think how you would search for it too eaily, though). I haven't used the form myself, but we should be able to get it to work smoothly. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---