I need help with making queries. I keep reading
http://docs.djangoproject.com/en/dev/ref/models/querysets/
http://docs.djangoproject.com/en/dev/topics/db/queries/

but neither of those pages has exactly what i want nor explains why i
cant get what i want with existing queries.

Ill first post existing models here:

class Trans(models.Model):
        keel = models.ForeignKey(lang)
        content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        content_object = generic.GenericForeignKey("content_type",
"object_id")
        name= models.CharField(max_length=500)
        def __unicode__(self):
                return unicode(self.name)

class Poll(models.Model):
        name = generic.GenericRelation(Trans)
        pub_date = models.DateTimeField('date published')
        active = models.BooleanField()
        def __unicode__(self):
                return unicode(self.name)

What im trying to achieve with query is to retrieve the actual
translation (from trans model) instead of poll name.

I wrote model manager for it -

        def tname(self):
                q = ContentType.objects.get_for_model(self)
                z = Trans.objects.get(content_type__pk=q.id,
object_id=self.id).exclude(keel=2)
                t = z.name
                return t

What i fail to understand is how this query can retrieve 2 objects not
one, because i keep getting this error:

Caught an exception while rendering: get() returned more than one
Trans -- it returned 2! Lookup parameters were {'object_id': 1,
'content_type__pk': 11}

Doesnt the exclude work?

There is 2 translations for each poll. one with language 1 and one
with language 2.

This also gives me 2 results
z = Trans.objects.filter(poll = self)
q = z.get(keel = 1)
t = q.name

Error was :  Caught an exception while rendering: get() returned more
than one Trans -- it returned 2! Lookup parameters were {'keel': 1}

What i fail to understand is, that when i use enough filters to filter
results down to 1 - then i cant get .name value from the result, but
when i use get instead of filter i get too many results even though i
use exclude or additional parameters like keel = 1.

Please help me understand how queries are supposed to work and how can
i get what i want.

Alan.

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

Reply via email to