Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Using Databases in Python Meet Peewee Queries Are Your Friend

Chih-Wei Hsu
Chih-Wei Hsu
11,132 Points

student_record ? a new table or a new column??

In the lesson where we create student_record to avoid duplicate usernames in the Student table, and then we use student_record.point to populate points. All of these seem like we've created a new table called student_record in the same database, with a column called student_record that holds the usernames, and a column called point in the student_record table. Is my understanding of student_record correct?? Or is student_record another column in the Student table, and student_record.point is also another column in the Student table??

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,030 Points

In the line:

                student_record = Student.get(username=student['username'])

student_record points to a specific saved instance of Student. student_record.points is the points attribute of this instance. After adding the points values, this instance is saved in the Student table using student.save(). Said another way, student_record points to a row in the Student table. student_record.points points to the points column in the Student table for that row.

pawkan kenluecha
pawkan kenluecha
26,303 Points

Hello, Is it possible to use only student['username'] ?

student_record = Student.get(student['username']) 

Does this means Student.get is pass by reference and not by value?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,030 Points

Mike d'julio, all Python is “pass by object reference”.

Post back if you need more help. Good luck!!!

Ahmad Faris
Ahmad Faris
1,656 Points

I don't think it's possible using that line of code... because for each Student we have two attributes , namely username and points and using Student.get (student['username']) will throw an error