Ok… I understand that I need to access the user object… From what I have been taught that is using dot notation to get into the user object. so…
to get the name it should be user.name and email should be user.email, so to access this in the document construct it should be
document = {“name” : user.name, “email” : user.email, “movie_id”: movie_id, “comment” : comment, “date”: date}
This SHOULD create the document to insert in the insert command… But it appears that I am not accessing the user object.
Below is my code.
def add_comment(movie_id, user, comment, date):
"""
Inserts a comment into the comments collection, with the following fields:
- "name"
- "email"
- "movie_id"
- "text"
- "date"
Name and email must be retrieved from the "user" object.
"""
# TODO: Create/Update Comments
# Construct the comment document to be inserted into MongoDB.
comment_doc = {"name": user.name, "email": user.email, "movie_id": movie_id, "comment": comment, "date": date}
return db.comments.insert_one(comment_doc)
It seems I am messing up on the user object… But I tried user.get_user() but there is no get user… So… The only other thing I know of is to use dot notation and drill down into the user object like this… user.name and user.email
Am I on the right track?