Welcome to the Treehouse Community
Looking to learn something new?
nicole lumpkinCourses Plus Student 5,328 Points
What kind of object is student_record?
I am struggling to understand what kind of object student_record is. So far my understanding is that a Student object translates to three parts that create a whole table.
- The table itself (Student)
- A column (username)
- A column (points)
In the except block, student_record is defined as the following
except IntegrityError: student_record = Student.get(username=student['username']) student_record.points = student['points'] student_record.save()
This is where I lose the thread of reasoning re: what kind of obj student_record is. Working from within the parenthesis outwards, I know student['username'] accesses a string value(let's say 'Kenneth'). So now we have the following
student_record = Student.get(username='Kenneth')
- I'm assuming the .get() is a query? Y/n
- So when we query, do we always use a unique attribute/column as the query?
- Is this considered a query instance/object?
-An instance/obj that acts as a handle to the whole row in which it resides?
-An object that allows us to gain access to other attributes/columns within the same row via dot notation? The points attribute for example?
student_record.points = student['points']
Whoever answers this, I'd like to thank you in advance!
Hi to add to Jorge answer student_record is an instance of the Student class which inherits from the Peewee model class i.e not sure what you are looking at, hwoever, I would presume the Student class looks something like this
class Student(Model): username = CharField(unique=True) points = IntegerField()
student_record is an obj oreturned by the Student class based on the query username == 'Kenneth' get() is a query and gets a single record. If you want to get all students with points greate that 10 you would use a SQL query such as:
max_points = Student.select().where(Student.point => 10).order_by(Student.username)
if you want to get all entries in Student you can just use
I hope this helps a little and excuse me if I stated something incorrect :)