здесь я фильтрую 'rawitem', используя фильтр django, но в моем шаблоне я не могу отобразить форму, что я делаю неправильно
models.py
class Purchase(models.Model):
rawitem=models.ForeignKey(Rawitem, on_delete=models.CASCADE)
quantity=models.PositiveIntegerField(blank=True)
date=models.DateTimeField(default=timezone.now)
supplier=models.ForeignKey(Supplier, on_delete=models.CASCADE)
total=models.PositiveIntegerField(editable=False)
receives=models.BooleanField(default=False)
counts=models.PositiveIntegerField(null=True, blank=True)
sgst=models.FloatField(null=True, blank=True, editable=False)
grand_total=models.PositiveIntegerField(editable=False)
filters.py
from material_transaction.models import Purchase
import django_filters
class UserFilter(django_filters.FilterSet):
class Meta:
model = Purchase
fields = ['rawitem']
views.py
from django.shortcuts import render
from material_transaction.models import Purchase
import datetime
from .filters import UserFilter
# Create your views here.
def report(request):
return render(request,'report/report.html')
def purchase_report(request):
user_list = Purchase.objects.all()
purchase_report = UserFilter(request.GET, queryset=user_list)
return render(request, 'report/purchase_report.html',
{'purchase_report':purchase_report})
urls.py
from django.urls import path
from .import views
urlpatterns = [
path('',views.report, name='report'),
path('purchase_report',views.purchase_report, name='purchase_report'),
]
и мой шаблон
<form method="get">
{% csrf_token %}
{{ filter.form.as_p }}
<button type="submit">Search</button>
</form>
это мои установленные вещи
Django==2.1.5
django-crispy-forms==1.7.2
django-filter==2.1.0
pytz==2018.9