I have a Django auction project (CS50 course assignment) and I have the following function in views.py:
def show_item(request, items):
items = Listing.objects.filter(item = items)
for item in items:
ends = item.date + timedelta(days=7)
return render(request, "auctions/show_item.html",{
"items":items, "ends": ends
})
This allows me to display the item and its end date. My question is, since there is only one iteration in the loop (I'm showing a single item for auction on the template view), isn't there a cleaner way of doing
ends = item.date + timedelta(days=7)
?
(i.e. just need to obtain the item date field in the model)
Without the need of the for loop?
I tried : ends = items.date + timedelta(days=7)
but get an error?