Monday, July 22, 2013

Problem with chaining filters

1.
I wrote this to make python shell only list Words that have no translation.

>>> Word.objects.filter(translation='')
[<Word: Page>, <Word: Paper>, <Word: Pencil>]


2.
How can I use the above filter result and chain it,
so that I can make a new list that displays the field "articulate",
from the other table "Pronunciation"?


01 class Word(models.Model):
02    word = models.CharField(max_length=200)
03    translation = models.CharField(max_length=120, blank=True, null=True)
04    def __unicode__(self):
05        return self.word
06  
07 class Pronunciation(models.Model):
08    word = models.ForeignKey(Word)
09    articulate = models.CharField(max_length=200)
10    def __unicode__(self):
11        return self.articulate

 

--
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