0

I got so much trouble forming the right query to get my result...

from django.db import models
from django.contrib.auth.models import User

class GeoCatch(models.Model):
    user_me = models.ForeignKey(User, null=True, related_name='me')
    user_he = models.ForeignKey(User, null=True, related_name='he')
    permission_he = models.BooleanField(default=False)
    permission_me = models.BooleanField(default=False)

The query I need:

get names in djangos User table of various user_he which have user_me = 1 and have permission_he = True and permission_me= True

This and a couple other querys were not successful...

get_friends =  User.objects.values_list('username').filter(geoCatch__user_me=id)/
.filter(permission_he = True).filter(permission_me= True)

Gives me Error:

django.core.exceptions.FieldError: Cannot resolve keyword 'geoCatch' into field.

2 Answers 2

2
friends = GeoCatch.objects.filter(user_me=User.objects.get(pk=id)) \
                    .filter(permission_me=True) \
                    .filter(permission_he=True).user_he_set.all()
Sign up to request clarification or add additional context in comments.

1 Comment

okay sorry: i set id to 1 and now it gives me : AttributeError: 'QuerySet' object has no attribute 'he_set'
1
# id is an id of a user object
get_friends =  User.objects.values_list('username', flat=True)\
    .filter(me__user_me__id=id, me__permission_he = True, me__permission_me= True)

2 Comments

this works! if id is set by the user object...sorry...hard to understand especially the __me stuff...
hmm it just gives me the username of the id so many times like it has found matching permission_he and permission_me...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.