I'm trying to use on_delete
with my models but my IDE is asking me for: collector, fields, sub_objs, using (i.e. ..., on_delete=models.PROTECT(collector, fields, sub_objs, using))
.
Can someone please tell me what these are and give me a quick example because I can find them documented anywhere :(
Ignore your IDE. It is trying to get you to call the models.PROTECT
function, which does indeed take those arguments. But you actually want to pass the function itself:
my_field = models.ForeignKey(..., on_delete=models.PROTECT)
ie without the parentheses that would call the function.
(Insert rant about using an IDE with a dynamic language here...)
Import like:(Python 2.7)
from django.db.models.deletion import PROTECT
Then you can use it directly.
category = ForeignKey(TCategory, PROTECT, null=False, blank=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With