Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to modify existing model instance in django?

In Django, I am trying to modify the title of the existing book with id. My views.py file consists of

b=Books.objects.filter(book_id__iexact=book)
b.title = "Narnia"
b.save()

I am getting error and unable to save the model instance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try using get method instead of filter. When you use filter you are using a queryset object. Instead of using Books.objects.filter(book_id__iexact=book) try using b=Books.objects.get(book_id__iexact=book)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading