Save django object question.

Asked 2 years ago, Updated 2 years ago, 41 views

Hi, everyone. https://docs.djangoproject.com/en/1.10/topics/db/queries/#updating-multiple-objects-at-once

This is the object storage question in

My code is


In [23]: for item in ActressInfo.objects.values_list('birth', flat=True):
    ...:     string = re.sub(r'(\d+)\w(\d+)\w(\d+)\w',r'\year\February\3',item)
    ...:     ...:     string.save()

This is.

Error message is


AttributeError: 'str' object has no attribute 'save'

I looped the query set just like the manual, but I don't know what the problem is. All() instead of values_list() is saved. I want to save specific fields Is there any other way other than values_list?

django python

2022-09-22 12:34

1 Answers

What you changed with the item is a variable called string, and it seems that there is an error in updating this string to the item.

I think the current string is just a str object that normalizes the item.

Also, value_list means the output that lists the value of the birth part of ActressInfo above.

objects.all()ActressInfo objects are imported into ActressInfo objects, so when you put each object in the item and execute a for repeat statement, each ActressInfo object is .save()It was possible.

I may not be accurate, but I hope it was helpful^

^


2022-09-22 12:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.