Hello! I have an img (photo) field in the user's Django model. I need to delete photos for all users. I try to write the corresponding request in the API, there were attempts to User.img.all().delete , p=User.objects.all().get , then p.img.all().delete , for user in p: user.img.delete() , but it fails to write correctly, various errors are for user in p: user.img.delete() . Can you please tell me how to do this?
|
1 answer
Use the update method for the QuerySet:
User.objects.all().update(img='') or img=None if your default field is null
- Thanks, it turned out! True, the error was first generated
mysql server has gone away. If I understood correctly, because of the default size of the request. At least after I changed it, the error was no longer issued. - Anastasia Novikova
|