[Django]-Setting up foreignkeys in loaddata for Django

6👍

You just need to use de pk of the object you want to link:

[
{
    "fields": {
        "first_name": "John",
        "last_name": "Doe",
        "middle_name": "G",
        "birthday": "1900-07-21",
        "password": "goforit123",
        "email": "John.Doe@gmail.com"
    },
    "model": "account_data.user",
    "pk": 1  // This is the pk you have to use
},
{
    "fields": {
        "user": 1,  // Use the pk, in this case you're referencing to John Doe
        "type": "dog",
        "color": "blue"
    },
    "model": "account_data.pets",
    "pk": 1
}
]
👤Gocht

Leave a comment