Hello,

I have a M2M field...

class A(models.Model):
    foo1 = models.ManyToManyField('B', related_name='foo1_set' ...)
    foo2 = models.ManyToManyField('B', related_name='foo2_set' ...)
    ...

When I run:

...foo.select_related()

I get all of the B entries related to A instance.

I would like to write a method similar to select_related() (I need to 
customize the query), but I am not sure how to implement such a query.

I have been hammering at this all day, and I gave up on the idea of writing 
my own select_related() method and I have most recently tried:

Failure #1:

Add the below method to class A:

def custom_select_related(self):
    if self.foo1:
        return self.foo1.select_related()
    elif self.foo2:
        return self.foo2.select_related()
    else:
        return None

Failure #2:

Added the similar method as above, except I replaced replaced 
select_related() with foo1/foo2_set.

...

What I really need is to implement similar functionality as 
select_related()... I am just not sure how or where. Is this a model 
manager?

Could someone kick me in the right direction here? :D

Please let me know if I can post more code and/or explain my situation 
better.

Thanks so much!

Cheers,
Micky 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/WGd5bnh1OEI3WlFK.
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