Hello! I followed the instructions in Intermediate Concepts for “Adding User-Uploaded Images” but got stuck trying to figure out how to restrict the user to a single image upload. I would like my “thing” to have just one image that can be replaced when a new one is added. I tried this on views.py, thinking I could just limit what was displayed on the detail page, but it showed the first image, not the last one uploaded. What is the best way to go about this?
def adventure_detail(request, slug):
# grab the object
adventure = Adventure.objects.get(slug=slug)
social_accounts = adventure.social_accounts.all()
uploads = adventure.uploads.all()[:1]
# and pass to the template
return render(request, 'adventures/adventure_detail.html', {
'adventure': adventure,
'social_accounts': social_accounts,
'uploads': uploads,
})