from django.conf import settings from django.db import models class Article(models.Model): author = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, )
Here is what the above code is Doing:
1. We’re importing the settings module.
2. We’re importing the models module.
3. We’re defining a new model called Article.
4. We’re defining a foreign key field called author.
5. We’re telling Django that the author field is a foreign key to the User model.
6. We’re telling Django that when a User is deleted, all of the articles written by that user should be deleted as well.