Friday, August 9, 2013

How can I order my list based on a field in a different table?

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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment