I’m still not able to recreate the problem you’re describing. Here are the classes I’m using:
class PStatus(models.Model):
statustext = models.CharField(max_length=20, blank=True)
class Department(models.Model):
name = models.CharField(max_length=50)
class Erfasst(models.Model):
status = models.ForeignKey(PStatus, models.PROTECT)
approved_at = models.DateTimeField(null=True, blank=True)
dept = models.ForeignKey(Department, models.SET_NULL, null=True, blank=True)
@classmethod
def from_db(cls, db, field_names, values):
instance = super().from_db(db, field_names, values)
instance._old_status_id = instance.status_id
instance._old_approved_at = instance.approved_at
return instance
Deleting an entry from Department that is being referenced by Erfasst causes the dept
field to be set to null as expected.