#5 Create course endpoint. Added messages to all db migrations

This commit was merged in pull request #30.
This commit is contained in:
2023-04-06 15:23:10 -04:00
parent 20f0309c5c
commit 12498c2ee8
5 changed files with 52 additions and 9 deletions

View File

@@ -37,11 +37,24 @@ class User(UserMixin, db.Model):
if new_user and "password" in data:
self.set_password(data["password"])
class Course(db.Model):
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String(128), index=True)
description = sa.Column(sa.Text, index=True)
instructor = sa.Column(sa.ForeignKey(User.id), index=True)
created_at = sa.Column(sa.DateTime, default=datetime.now())
created_at = sa.Column(sa.DateTime)
def from_dict(self, data):
for field in ["name", "description", "instructor"]:
if field in data:
setattr(self, field, data[field])
if not self.created_at:
self.created_at = datetime.now()
def to_dict(self):
d = {}
for f in ["id", "name", "description", "instructor", "created_at"]:
d[f] = getattr(self, f)
return d