Я пытаюсь ввести от пользователя выбор поставщика (2 варианта) и таймфрейм (3 варианта), с которого они хотят получить запрос. Я сталкиваюсь с вышеупомянутой ошибкой в том же. Ниже прилагаются соответствующие файлы.
HTML:
<form method="POST" action="/profiles/adminKaLogin/">
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="defaultInline1" name="inlineDefaultRadiosExample" value="1">
<label class="custom-control-label" for="defaultInline1">Vendor 1</label>
</div>
<!-- Default inline 2-->
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="defaultInline2" name="inlineDefaultRadiosExample" value="2">
<label class="custom-control-label" for="defaultInline2">Vendor 2</label>
</div>
<br>
<h3> Select time period</h3>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="defaultInlines1" name="inlineDefaultRadiosExample1" value="1">
<label class="custom-control-label" for="defaultInlines1">1 Month</label>
</div>
<!-- Default inline 2-->
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="defaultInlines2" name="inlineDefaultRadiosExample1" value="2">
<label class="custom-control-label" for="defaultInlines2">2 Months</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="defaultInlines3" name="inlineDefaultRadiosExample1" value="6">
<label class="custom-control-label" for="defaultInlines3">6 Months</label>
</div>
<br>
<button type="submit" class="btn btn-primary" name="form1">Submit</button>
</form>
models.py
class vendor(models.Model):
id = models.CharField(max_length=20, primary_key=True)
name = models.CharField(max_length=30)
class employee(models.Model):
name = models.OneToOneField(User, on_delete=models.CASCADE)
id = models.CharField(max_length=20, primary_key=True)
balance = models.IntegerField(default=0)
class transaction(models.Model):
vendor_id = models.ForeignKey(vendor, on_delete=models.CASCADE)
emp_id = models.ForeignKey(employee, on_delete=models.CASCADE)
debit = models.IntegerField()
credit = models.IntegerField()
timestamp = models.DateField(("Date"), default=datetime.date.today)
views.py
if 'form1' in request.POST:
d={}
vendor_choice = request.POST["inlineDefaultRadiosExample"]
date_choice = request.POST["inlineDefaultRadiosExample1"]
x = employee.objects.all()
y = vendor.objects.all()
if date_choice == 1:
d = transaction.objects.filter(vendor_id=y, emp_id = x, timestamp__gte = datetime.date.today() - datetime.timedelta(days=30))
elif date_choice == 2:
d = transaction.objects.filter(vendor_id=y, emp_id = x, timestamp__gte = datetime.date.today() - datetime.timedelta(days=60))
else:
d = transaction.objects.filter(vendor_id=y, emp_id = x, timestamp__gte = datetime.date.today() - datetime.timedelta(days=180))
print(d)
return render(request, 'profiles/adminKaLogin.html', {'model':d})
Интересно, почему эта проблема возникает? Любая помощь приветствуется.