I'm making an app atm where I get dummy data from a json file. My filed in this file looks like this:
{
"model": "card.model",
"pk": 2222,
"fields": {
"meal_1": 5555,
"meal_2": 5556,
"meals": "[5555, 5556]"
}
}
{
"model": "meal.model",
"pk": 5555,
"fields": {
"name": "Pizza",
"vagan": True
}
}
{
"model": "meal.model",
"pk": 5556,
"fields": {
"name": "Sandwich",
"vagan": False
}
}
I have a Meal class that contains: name, photo, description. I have also Card class that gets info right from json file.
class Card() {
meal_1 = models.ForeignKey(
Meal,
related_name='meal_1"
)
meal_2 = models.ForeignKey(
Meal,
related_name='meal_2"
)
meals=[] ??
}
How can I add an array field that will contain a reference to these meals. What I want to achieve is loop over this meals and place into django template. Now I do this by reference to each filed: instance.meal_1.name... etc.