I am trying to get a value from a queryset, but i keep getting this error that says 'bool' object is not subscriptable.
I have a queryset that looks like this tax_rate_fee = TaxRate.objects.filter(country=cartorder.country).exists() and i am checking to see if a specific country exists in the Queryset, then i want to grab a value from the queryset and perform some operation.
This is my code
tax_rate_fee = TaxRate.objects.filter(country=cartorder.country).exists()
if tax_rate_fee:
cartorderitem.vat = 5 * tax_rate_fee['rate']
this is the tax rate fee model
class TaxRate(models.Model):
country = models.CharField(max_length=200)
rate = models.IntegerField(default=5, help_text="Numbers added here are in percentage (5 = 5%)")
active = models.BooleanField(default=True)
From this, it seems i am not returning a queryset, but instead checking to find whether a queryset contains any items.
I also printed the tax_rate_fee and got back True.
So how do i check if an item exist and also grab a value from the queryset.
this is what i tried doing now: Check if the len() of tax_rate_fee queryset is equal to 1, then run the command.
I then got this error QuerySet indices must be integers or slices, not str. that is why i tried converting the tax_rate_fee to integer here int(tax_rate_fee['rate']).