Replying to myself, this is the temporary solution to the issue, I
described yesterday:

class Element(...)
    ...
    def get_categories(self):
        return Category.objects.distinct().extra(
            tables=['elementapp_element_categories AS eec'],
            where=['categoryapp_category.id=eec.category_id',
'eec.element_id=%d' % (self.id or 0)],
        )

Now I can use
e.get_categories()
instead of
e.categories.all()
and get the related objects without errors.

Regards,
Aidas Bendoraitis [aka Archatas]



On 4/4/07, Aidas Bendoraitis <[EMAIL PROTECTED]> wrote:
> Hello!
>
> I am using per-object-permission branch and experiencing the same
> problem, mentioned in the closed ticket #2201: can't get the
> many-to-many-related objects from the side of the model which defines
> the many-to-many relation, although no problem vice versa.
>
> Let's say I have
>
> class Category(models.Model):
>     title = models.CharField(...)
>
> class Element(models.Model):
>     title = models.CharField(...)
>     categories = models.ManyToManyField(Category, blank=True)
>
>
> Then
> >>> c = Category.objects.all()[0]
> >>> c.element_set.all() # works OK
> []
>
> But
> >>> e = Element.objects.all()[0]
> >>> e.categories.all() # displays an error
> # bla bla bla
> TypeError: Cannot resolve keyword 'element' into field
>
> Is it the problem with the branch? If so, could someone merge the
> current trunk to the per-object-permission branch? Or what would be
> the circumventing of the problem, that is, how could I get all the
> categories for the Element instance?
>
> By the way, I tried to import models both: using project name and not
> using it. The results are the same.
> I am using MySQL if it may matter.
>
> Has anybody experienced the problem using the latest trunk?
>
> Regards,
> Aidas Bendoraitis [aka Archatas]
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to