Foreign Key Field



    Django Public Recipes

    The code above creates a foreign key in the RelatedModel to link to the current model. When the related model is deleted, the related model's on_delete attribute is invoked, which in turn calls the cascade method on the current model.

    Library: django

    Shortcut: django.field.foreignkey

    fieldName = models.ForeignKey(RelatedModel, on_delete=models.CASCADE)
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.