ForeignKey missing related_name

ORM queries are more readable and relationships more explicit when related_name is specified.

The related_name attribute specifies the name of the reverse relation from the related model back to the model.

Django automatically creates a related_name if related_name is not set. Django uses the lower-case name of the model with the suffix _set.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
models.py
1
+
class BlogPost(models.Model):
2
+
    post = models.ForeignKey(User, on_delete=models.CASCADE)

ORM queries are more readable and relationships more explicit when related_name is specified.

Read more
3
+
	
4
+
def get_user_blog_posts(user):
5
+
    return user.blogpost_set.all()
Update models.py

Instantly check if you have this issue for free

    Works with tools you use

    Read about how it works.