1) The model Word does not have the votes field, you cannot order the field it's not possessed.
2) You have to build a relation between the models first, check the relationships from Django Doc https://docs.djangoproject.com/en/dev/topics/db/models/#relationships On Friday, August 9, 2013 10:04:47 PM UTC+8, Pepsodent Cola wrote: > > 1.) > How can I order my list based on a field in a different table? > > return Word.objects.filter(direct_transl_word='') > > The above I want to do something like this where the field ('-votes') is > located at table Altword. > Nothing happens when I use this though, don't understand why? > > #return > Word.objects.filter(direct_transl_word='').order_by('-votes') > > > 2.) > My *altword_list.html* viewpage breaks whenever I try to use query for my > other table Altword. > > #return Altword.objects.filter(rosword__direct_transl_word='') > #return Altword.objects.filter(word__direct_transl_word='') > > #_______________________________________________________________________________ > > *AltwordlistView* > class AltwordlistView(generic.DetailView): > model = Word > #model = Altword > template_name = 'navi_polls/altword_list.html' > context_object_name = 'poll' > > def get_queryset(self): > # Filter 5 > return Word.objects.filter(direct_transl_word='') > #return > Word.objects.filter(direct_transl_word='').order_by('-votes') > #return Altword.objects.filter(rosword__direct_transl_word='') > #return Altword.objects.filter(word__direct_transl_word='') > > #_______________________________________________________________________________ > > *Models* > class Word(models.Model): > rosword = models.CharField(max_length=200) > direct_transl_word = models.CharField(max_length=120, blank=True, > null=True) > pub_date = models.DateTimeField('date published') > > def __unicode__(self): > return self.rosword > > #_______________________________________________________________________________ > > *Models* > class Altword(models.Model): > rosword = models.ForeignKey(Word) > alt_ros_word = models.CharField(max_length=200) > alt_transl_word = models.CharField(max_length=200) > articulate = models.CharField(max_length=200) > *votes* = models.IntegerField(default=0) > pub_date = models.DateTimeField('date published') > > def __unicode__(self): > return self.alt_ros_word > > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.

