Skip to content

How to set ForeignKey on_delete in EXTRA_MODEL_FIELDS setting? #2063

Closed Answered by tym-xqo
tym-xqo asked this question in Q&A
Discussion options

You must be logged in to vote

OK actually I got it, and was misunderstanding the structure of the EXTRA_MODEL_FIELDS sequences. Keyword arguments like on_delete are expected in the final dictionary portion of the field, where I already had "null": True, not in the tuple before with members.Student. So the working code was like:

EXTRA_MODEL_FIELDS = (
    (
        "cartridge.shop.models.CartItem.student",
        "ForeignKey",
        ("members.Student",),
        {"null": True, "on_delete": models.CASCADE},
    ),
    (
        "cartridge.shop.models.OrderItem.student",
        "ForeignKey",
        ("members.Student",),
        {"null": True, "on_delete": models.CASCADE},
    ),
)

(I also imported django.db.models

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tym-xqo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant