Skip to main content
Django Code Completion Medium +20 XP

Model ForeignKey

Complete the relationship field.

DjangoFill in the blank
author = models.___(User, on_delete=models.CASCADE)

Type the missing code

Show answer and explanation

Answer: ForeignKey

ForeignKey creates a many-to-one relationship. on_delete=CASCADE deletes related posts when the user is deleted.

Hint: Which field creates a many-to-one relationship?

What this challenge tests

Code Completion in Django: models, relationships.

Related challenges