Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions flask-connexion-rest-part-2/rp_flask_api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from config import db, ma

Expand All @@ -9,7 +9,9 @@ class Person(db.Model):
lname = db.Column(db.String(32), unique=True)
fname = db.Column(db.String(32))
timestamp = db.Column(
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
db.DateTime,
default=lambda: datetime.now(timezone.utc),
onupdate=lambda: datetime.now(timezone.utc),
)


Expand Down
2 changes: 1 addition & 1 deletion flask-connexion-rest-part-2/rp_flask_api/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update(lname, person):
existing_person.fname = update_person.fname
db.session.merge(existing_person)
db.session.commit()
return person_schema.dump(existing_person), 201
return person_schema.dump(existing_person)
else:
abort(404, f"Person with last name {lname} not found")

Expand Down
10 changes: 7 additions & 3 deletions flask-connexion-rest-part-3/rp_flask_api/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

from config import db, ma
from marshmallow_sqlalchemy import fields
Expand All @@ -10,7 +10,9 @@ class Note(db.Model):
person_id = db.Column(db.Integer, db.ForeignKey("person.id"))
content = db.Column(db.String, nullable=False)
timestamp = db.Column(
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
db.DateTime,
default=lambda: datetime.now(timezone.utc),
onupdate=lambda: datetime.now(timezone.utc),
)


Expand All @@ -28,7 +30,9 @@ class Person(db.Model):
lname = db.Column(db.String(32), unique=True)
fname = db.Column(db.String(32))
timestamp = db.Column(
db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
db.DateTime,
default=lambda: datetime.now(timezone.utc),
onupdate=lambda: datetime.now(timezone.utc),
)

notes = db.relationship(
Expand Down
2 changes: 1 addition & 1 deletion flask-connexion-rest-part-3/rp_flask_api/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def update(note_id, note):
existing_note.content = update_note.content
db.session.merge(existing_note)
db.session.commit()
return note_schema.dump(existing_note), 201
return note_schema.dump(existing_note)
else:
abort(404, f"Note with ID {note_id} not found")

Expand Down
2 changes: 1 addition & 1 deletion flask-connexion-rest-part-3/rp_flask_api/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update(lname, person):
existing_person.fname = update_person.fname
db.session.merge(existing_person)
db.session.commit()
return person_schema.dump(existing_person), 201
return person_schema.dump(existing_person)
else:
abort(404, f"Person with last name {lname} not found")

Expand Down
Loading