Running query in Django view

100 Views Asked by At

I have some amount which I am getting from a payment gateway database. Based on the amount that User has bought, I want to fetch some field value from Model. Below is my model.

class Subscription(models.Model):
    """
    Add Subscription Pack by Admin
    """
    pack_name = models.CharField('Subscription Name', max_length=255)
    price = models.PositiveIntegerField('Subscription Price',)
    no_resume = models.IntegerField('No. of Resume User can Access')

    def __str__(self):
        return self.pack_name

So if certain price value in the table matches with amount in the payment gateway db, I want to fetch the corresponding no_resume value from Subscription model and append it to a list. Below is the sql that I want to perform in Django view.

SELECT no_resume from Subscription WHERE price = amount

Thanks in advance..

1

There are 1 best solutions below

0
On
Subscription.objects.filter(price=amount).values('no_resume')

then you will get a list of no_resume.