As I still haven't solved this, any suggestions would be appreciated.
On Jun 26, 10:16 pm, Tony wrote:
> Alex,
> I did it your way and although it does return the intersected sets
> correctly, it is not exactly what I want because I need those sets to
> be returned with
Alex,
I did it your way and although it does return the intersected sets
correctly, it is not exactly what I want because I need those sets to
be returned with their respective model A objects. So, referring back
to the end result of my example above:
a1 to (b1,), a2 to None, a3 to (b1,)
I want
It means I want some objects of type B to be filtered within their
parent relation of model A. I am about to try Alex's suggestion, but
any other suggestions would be great too and I will let you guys know
if it works.
On Jun 24, 3:36 pm, Nikhil Somaru wrote:
> When you say
When you say 'filter' do you mean that you want some objects removed (i.e.
filtered), or, do you mean that you want all the A's returned to be in a
list that is sorted?
On Fri, Jun 24, 2011 at 5:55 AM, Tony wrote:
> Nikhil,
> This email will be significantly shorter than
Hi, Tony,
I would do something like this:
# b2 makes a connection
b_qs = b.objects.filter(b_rel=b2) # - all friends of b2
iter = ( a_inst.b_set & b_qs for a_inst in a.objects.all() ) # here we
make an iterator which give you a queryset of the intersection of
a.b_set and friends of b2.
On Jun 24,
Nikhil,
This email will be significantly shorter than the one I wrote 5
minutes ago before my laptop ran out of battery and failed to get
sent. I didn't explain this clearly so I am going to give an example
(a much smaller one than the one I jsut wrote).
Lets say I have 3 object As (a1, a2, a3)
Hi Tony,
Try this:
q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
your_b1_instance
q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with B.B =
your_b2_instance
result = set(q1).intersection(set(q2)) #gives you the A's that are common to
both sets.
You have the question I was asking correct, your notation was fine.
The only thing I should add is I want to return all A, but filter my
"B1"s (as you put it) for each A. I will post my models if need be,
but they are on another computer and its not convenient right now. In
the meantime, do you
It is very hard to read your message. Please format it appropriately next
time. Avoid repeating variable names and mixing classes with instances.
Could you post your models here?
Are you defining the following structure:
A hasMany B;
B hasMany A;
B hasMany B;
So you want* A such that
I have two models with a manytomany through relation (A and B). B has
a self referential manytomany relation (a userprofile model). How
could I filter objects of model B per each relationship with model A?
So lets say 3 arbitrary model A objects have 20 model B object
relations each. I want to
10 matches
Mail list logo