I am building a bike rental ap.
frontend: user selects the start and end dates and get all the available bikes in a list view, bikes with categories and appropriate price.
Price: price is calculated on 2 conditions. Vehiclecategory and duration.(as price has duration slabs.
1-3 days = 145$ sporty
1-3 days = 145$ scooter
4-7 days = 2004 sporty
4-7 days = 2004 scooter etc.
Duration can only be achieved from the chosen dates from the form in front-end, which gets converted to days.
I need to pass these days as duration to get the appropriate price and display it under each category accordingly in a list view.
MODELS.PY
class 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
VIEWS.PY
class 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')
if start_date and end_date:
start_date = datetime.strptime(start_date, "%m/%d/%Y").date()
end_date = datetime.strptime(end_date, "%m/%d/%Y").date()
duration = (end_date - start_date).days +1
vehiclecategory= VehicleCategory.objects.all()
context = {
'vehiclecategory1': vehiclecategory.filter(main_category= 'E-Cycle'),
'vehiclecategory2': vehiclecategory.filter(main_category= 'E-Scooter'),
'form':CartQuantityForm(),
'dateform': DateForm()
}
return render(request, self.template_name, context )
here I get the duration, how can I pass this in the model method price parameter and get the above Queryset to work????"""