I have a Photo class which inherits from Content model like this:
class Content(models.Model):
added = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Photo(Content):
file = models.ImageField(upload_to='photos/')
def __unicode__(self):
return self.caption and self.caption or ''
As can be seen, Content itself is not abstract. By a ModelForm, I am uploading photos. But, if saving of the Photo fails for some reason, an orphan Content instance is left. I guess the instance for the parent model is created before the Photo instance is saved but if photo fails, the parent is not cleaned-up.
Is this a bug on Django side? How can this be prevented?