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 trial

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,426 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,426 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