1

I'm trying to clear all the data of a certain field within a model for all of the objects. Something like this:

#models.py
class A(models.Model):
    someProperty = models.ManyToManyField(SomeModel)
#views.py
object = A.objects.all()
object.someProperty.all().clear()

I understand this is probably simple but I have been looking through the django documentation and haven't been able to find a good way to do this. Any help is greatly appreciated :)

Nick
  • 49
  • 6
  • might be looking for the update queryset method https://docs.djangoproject.com/en/3.1/ref/models/querysets/#update – AMG Mar 09 '21 at 03:09
  • @AMG Since this is a `ManyToManyField`, I can't call that can I? – Nick Mar 09 '21 at 03:11
  • I got too excited. Missed the many to many. One moment. – AMG Mar 09 '21 at 03:13
  • 1
    does this answer help: https://stackoverflow.com/a/32553176/4872140 You don't have a through table specified so you'll need to use the _meta to get the table name – AMG Mar 09 '21 at 03:17
  • this one might be of interest: https://stackoverflow.com/a/43798313/4872140 Goes at it from the SomeModel side `some_model.a_set.clear()` although I don't think that will get exactly what you want. – AMG Mar 09 '21 at 03:24

0 Answers0