0

models.py

class Friend(models.Model):
    creator = models.ForeignKey(Individual, related_name="friendship_creator_set", blank=True, null=True)
    friend = models.ForeignKey(Individual, related_name="friend_set", blank=True, null=True)
    active = models.BooleanField(default=False, blank=True)
    confirm = models.BooleanField(default=False, blank=True)
    created_at = models.DateTimeField(auto_now_add=True, auto_now=False)
    modified_at = models.DateTimeField(auto_now_add=False, auto_now=True)

I am adding this two query to get the result:

Friend.objects.filter(creator_id=value, confirm=True).count() + Friend.objects.filter(friend_id=value, confirm=True).count()

How can convert it to a single queryset in Django?

1 Answer 1

1

You just need to do an or condition..

from django.db.models import Q
Friend.objects.filter(Q(creator_id=value) | Q(friend_id=value), confirm=True).count()
Sign up to request clarification or add additional context in comments.

Comments

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.