6👍
Use the clear
method.
Removes all objects from the related object set:
b = Blog.objects.get(id=1)
b.entry_set.clear()
Note this doesn’t delete the related objects – it just disassociates them.
Just like remove(), clear() is only available on ForeignKeys where
null=True.
- [Django]-Django: Values_list returns id from choice field instead of name
- [Django]-Specify choices in model and RadioButton in ModelForm renders not selected value "——"
0👍
use the related objects clear method clear clear()
to dissociate all Foo related objects
moo.foo_set.clear()
to delete objects use delete()
queryset method
Foo.objects.all().delete()
you can delete by one object using filter()
default manager method
Foo.objects.filter(name='moo1').delete()
- [Django]-Pass a lazy translation string including variable to function in Django
- [Django]-Django – split view.py to small files
Source:stackexchange.com