I’m not too sure why but I have this problem whereby it states “Attribute undefined: .objects of Trip: Trip”. Below is my views.py. It appears to be caused by the .objects.all() as this is highlighted in my Wing Pro IDE.
After looking this up on google, someone suggested to put objects = models.Manager() in the model, which actually works but I don’t think this is the correct way to resolve this. I am sure I’ve been a bit of a donkey along the way and omitted something vital but I’ll be damned if I can spot it. I think this issue would be a good candidate for the forum and I will certainly add this.
from django.shortcuts import render
from logbook.models import Trip
def index(request):
trips = Trip.objects.all()
return render(request, 'index.html', {
'trips': trips,
})
def trip_detail(request, slug):
# grab the object...
trip = Trip.objects.get(slug=slug)
# and pass to the template
return render(request, 'trips/trip_detail.html', {
'trip': trip,
})