I have two models:
A(models.Model):
field = models.IntegerField()
B(models.Model):
f = models.ForeignKey(A)
And in admin panel I have custom action, which clears(resets) some info in Model A:
def clear_something(modeladmin, request, queryset):
queryset.update(field=0)
How could I make custom action clear_something delete all related Model B entries?
Assuming queryset is a set of A’s, you should be able to loop over them and delete the ‘b_set’ (reverse FK lookup) of each, like so:
Alternatively, use B’s model manager: