[Answered ]-Can't call save() in Django Model? Gets: AttributeError: 'unicode' object has no attribute 'save'

2👍

The problem is at:

gallery_titles = Gallery.objects.get(pk=e).titles
gallery_titles.save()

When you do Gallery.objects.get(pk=e), it returns you a model instance, however then you retrieve it’s titles attribute which I guess is a string (unicode). So at that point, gallery_titles is a sting which you try to save on the next line, but unicode class does not have a method save which causes an error.

As a side note, it’s probably not the best idea to put logic code directly inside a class definition. You can factor your logic into class methods which would be much more appropriate. When you call a class method inside it’s definition you are still defining a class attribute.

Leave a comment