'Thing' object has no attribute 'uploads'


#1

in second book, adding user-uploaded images,I got the error ‘Thing’ object has no attribute ‘uploads’,here is my code [views.py and models.py][1]

can any one help me figure out the problem ,thank you
[1]: http://stackoverflow.com/q/35764638/5678590


#2

I got to know why:
uploads = thing.uploads.all(),should be —> uploads = Upload.objects.filter(thing=thing),it works
also another way ,
uploads = thing.uploads.all() —> uploads = thing.upload.all() ,it works


#3

Thanks for letting us know!


#4

actually , it is my fault,I typo the models.py in class Upload(**),thing = models.ForeignKey(Thing, related_name=“uploads”)—>thing = models.ForeignKey(Thing, related_name=“upload”),
“upload” should be “uploads”,
in fact no need to change views.py ,I have to correct the models.py ,.^ ^