models are: from django.db import models from userprofile.models import Lecturer, UserProfile from django.contrib.auth.models import User from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django import forms
class Category(models.Model): name = models.CharField(max_length=50) lecturer = models.ManyToManyField(Lecturer) description = models.TextField(null=True, blank=True) data = models.TextField(help_text='This is the embedded playlist from SVP', null=True, blank=True) priority = models.IntegerField(default=50) def data_chunk(self): return "%s" % self.data # data_chunk.allow_tags = True def __unicode__(self): return self.name def get_category(self): return self.name class Meta: verbose_name_plural = "Categories" class Video(models.Model): category = models.ManyToManyField(Category) lecturer = models.ForeignKey(Lecturer) title = models.CharField(max_length=100) short_description = models.TextField(null=True, blank=True) description = models.TextField(null=True, blank=True) time = models.CharField(max_length=20, help_text='The length, time, of the video') is_trailer = models.BooleanField() is_descriptor = models.BooleanField(help_text='Use this description as the total lecture description') meta_title = models.CharField(max_length=100, blank=True) meta_desc = models.CharField(max_length=250, blank=True) meta_keywords = models.CharField(max_length=250, blank=True) def __unicode__(self): return self.title class Meta: verbose_name_plural = "Videos" problem view is from video.models import Video, Category from userprofile.models import Lecturer, UserProfile from django.shortcuts import render_to_response from django.http import HttpResponse, HttpResponseRedirect from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User def cat_view(request, id): cat = Category.objects.get(pk=id) vid = Video.objects.select_related().all().filter(category = cat).filter(is_trailer=False).filter(is_descriptor=True) return render_to_response('video/list.html', {'cat': cat, 'vid': vid, }, context_instance=RequestContext(request)) The problem is I can get at the foreign key lecturer with the select_related but I actually want to order_by the query set vid by a function that I can only get at within the individual video as in name = v.lecturer.get_surname() additional to this the categories per video need to be detailed as well (category the video belongs to is a ManyToMany) so my question is how to I order the query set by a foreign key that has a function to get the surname and also output on the template all the categories that the video belongs to? -- View this message in context: http://old.nabble.com/a-chicken-and-egg---help-please--tp30676218p30676218.html Sent from the django-users mailing list archive at Nabble.com. -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.