我想在模型上使用一种价格方法,该方法从前端表单接受参数并计算价格并显示在Listview中。
模型
VehicleCategory类:
@property
def price(self, duration):
for item in VehiclePrice.objects.all():
If item.vehicle_category.title == self.title and (duration >= item.slab.start and duration <= item.slab.end):
return item.net_price
观点 类HomeView(ListView):
template_name = 'app/home.html'
def get(self, request):
if request.method == "GET":
start_date = request.GET.get('start_date')
end_date = request.GET.get('end_date')
duration = end_date - start_date
return (duration.days + 1)
context = {
'vehiclecategory':VehicleCategory.objects.all()}
在这里,我得到了持续时间,如何在模型方法的price参数中传递该时间,并使上面的Queryset起作用??????