how to use filter in query twice in django

Viewed 84

I am trying to filter some data using this query,

get_members = PaymentDetails.objects.filter(participants_name=Participants.objects.filter(participants_name=Profile.objects.get(user=request.user)))

but I am getting this error The QuerySet value for an exact lookup must be limited to one result using slicing. My models looks like this

class Committee(models.Model):
    committee_creator = models.ForeignKey(Profile, on_delete=models.CASCADE)
    committee_name = models.CharField(max_length=100)

class Participants(models.Model):
    participants_name = models.ForeignKey(Profile, on_delete=models.CASCADE)
    participants_committee_name = models.ForeignKey(Committee, on_delete=models.CASCADE)
   
class PaymentDetails(models.Model):
    participants_name = models.ForeignKey(Participants, on_delete=models.CASCADE)
    participants_paid_status = models.BooleanField(default=False)
    participants_amount_paid = models.IntegerField()
1 Answers

try this i will assume that you have OneToOne Relationship between User and Profile.

get_members = PaymentDetails.objects.filter(participants_name__participants_name_id = request.user.profile.pk)
Related