Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdam Cameron
Python Web Development Techdegree Graduate 16,731 PointsPopulating the database with the JSON file
I'm all kinds of stuck here -- I've tried using loaddata
from the Django docs but I'm getting errors I don't understand and can't find anything about online, so I've decided to try the route of adding a class method to the Mineral
model that reads the JSON file and saves new instances based on its contents, and then just running it from the Django admin shell. There's some discussion and examples about it here:
https://teamtreehouse.com/community/writing-script-for-creating-model-instances-from-json
My model and class method are exactly like Alexey's in the first post, but upon calling the class method in the shell, I get KeyError: 'refractive index'
. I know this has to do with the fact that the first mineral/dictionary in the JSON file doesn't have a 'refractive index'. I've added default=''
to that field on my Mineral
model but it doesn't solve the problem. Any ideas? What have other people done to get over this initial hurdle?