Here some models:
class UserProfile(models.Model):
name = models.CharField(max_length=30)
email = models.EmailField(unique=True, db_index=True)
birthday = models.DateField()
class Photo(models.Model):
user = models.ForeignKey(UserProfile)
description = models.TextField(blank=True)
photo = models.ImageField(upload_to='img/photo')
Let’s say a user has 10 photos (10 objects of Photo model). When user deletes himself will all those 10 Photo database rows delete themselves automatically? (I’ve read docs, but English is not my native language, so I didn’t understand everything about the on_delete attribute.)
that’s the default behaviour, yes. you can change this behaviour with
on_deleteto get an illustration of this, try deleting a userprofile in the admin. it first shows a warning page, listing all related objects that will also get deleted