django - Ordering a Model -


i have following model --

class videocredit(models.model):     video = models.foreignkey(videoinfo)     profile = models.foreignkey('userprofile', blank=true, null=true)     normalized_name = models.charfield(max_length=100) 

i want order credits whether have profile, , noramlized_name, example --

# following entries   id   video             profile           normalized_name 1    terminator        terry gilliam     terry gilliam 2    terminator        james cameron     james cameron 3    dracula            null              bela lugosi  # order as: [james cameron, terry gilliam, bela lugosi] 

i tried doing ordering=['-profile_full_name', 'normalized_name'], order profile first, in reverse alphabetical order. if did profile_full_name instead, return without profile (a null field), @ beginning. how this? thank you.

update: got down this, working nicely:

recent_activity=[] object in recentactivity.objects.select_related.all()[:50]:     if object.event_type == 2:         credits_yes_profile = object.content_object.videocredit_set.exclude(profile=none).order_by('profile__full_name')         credits_no_profile = object.content_object.videocredit_set.filter(profile=none).order_by('normalized_name')         sorted_credits = list(credits_yes_profile) + list(credits_no_profile)         recent_activity.append((object, sorted_credits))     else:         recent_activity.append((object, '')) 

recent_activity=[] object in recentactivity.objects.select_related.all()[:50]:     if object.event_type == 2:         credits_yes_profile = object.content_object.videocredit_set.exclude(profile=none).order_by('profile__full_name')         credits_no_profile = object.content_object.videocredit_set.filter(profile=none).order_by('normalized_name')         sorted_credits = list(credits_yes_profile) + list(credits_no_profile)         recent_activity.append((object, sorted_credits))     else:         recent_activity.append((object, '')) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -