Re: Python dictionaries saved to models

2016-08-18 Thread Tim Graham
`apps` should be the first argument to the RunPython function. Using the import you mentioned is incorrect and may cause bugs if your models change in the future. On Thursday, August 18, 2016 at 10:10:43 AM UTC-4, Aaron Weisberg wrote: > > Nevermind- the good folks at Django didn't add: > > from

Re: Python dictionaries saved to models

2016-08-18 Thread Aaron Weisberg
Nevermind- the good folks at Django didn't add: from django.apps import apps in order to pull off this data migration On Thursday, August 18, 2016 at 8:40:26 AM UTC-5, Aaron Weisberg wrote: > > Thanks. > > However, when I write the function and try to run the data migration I run > into this e

Re: Python dictionaries saved to models

2016-08-18 Thread Aaron Weisberg
Thanks. However, when I write the function and try to run the data migration I run into this error: Enter code here...NameError: name apps is not defined That is coming from this line in the migration: Players = apps.get_model("team","Players") This is a copy/paste from the documentation.

Re: Python dictionaries saved to models

2016-08-18 Thread Tim Graham
Right, or even in a standalone script if a migration is more than you need: https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote: > > Maybe a data migration >

Re: Python dictionaries saved to models

2016-08-17 Thread Todor Velichkov
Maybe a data migration is what you are looking for. On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote: > > Great- thanks Tim. > > I understand the Python, but what I guess where I'm fuzzy is where to

Re: Python dictionaries saved to models

2016-08-17 Thread Aaron Weisberg
Great- thanks Tim. I understand the Python, but what I guess where I'm fuzzy is where to exactly put that code. Do I put it in the models.py? class.py? and how do I execute? That is the final piece of the puzzle for me. Thanks so much. Aaron On Wednesday, August 17, 2016 at 3:48:18 PM U

Re: Python dictionaries saved to models

2016-08-17 Thread Tim Graham
You need to transform your data dictionary so that the keys match the models field names and then you can use: players_data = [{'number': 1, ...}, {...}] for data in players_data: Player.objects.bulk_create(**data) (or something similar with bulk_create()) https://docs.djangoproject.com/en

Python dictionaries saved to models

2016-08-17 Thread Aaron Weisberg
Hi everyone, I have several dictionaries that I would like to import into my django project database, but I can't figure out exactly how. I have tried to implement through fixtures, through views and through loaddata, but I must be doing something wrong at every turn- so if someone could sugge