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 trialPavle Coric
10,753 Pointsis there a way to save steps to courses from the views.py file, or in the terminal/ not using the admin page?
I'm making a web app similar to this in the sense that I have a User object (think Course) and a whole bunch of devices that I want to register to the User (think Step). However I'm trying to do it from my views.py page and make a device registration html page that submits a DeviceForm to be saved. However, rather than Creating a Device object and updating the User object I'm running into the issue that my code is trying to create a new Device and User object which causes issues with the User object already existing. I'm using MongoDB as my database so the issue might be arising there.
1 Answer
Kenneth Love
Treehouse Guest TeacherSure. You can create the related model instance, say Step
, and then set it's FK to the first model. So, fetch a Course
, set that as the course
attribute's value on the Step
instance you just created. Save the Step
and now it'll show up in the Course
's step_set.all()
queryset.