#70 Add content model
This commit is contained in:
@@ -107,7 +107,7 @@ class Assignment(db.Model):
|
||||
created_at = sa.Column(sa.DateTime)
|
||||
|
||||
def from_dict(self, data) -> None:
|
||||
for field in ["name", "course_id", "description", "due_date"]:
|
||||
for field in ["name", "course_id", "description", "due_date"]:
|
||||
if field in data:
|
||||
setattr(self, field, data[field])
|
||||
|
||||
@@ -116,7 +116,30 @@ class Assignment(db.Model):
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
d = {}
|
||||
for f in ["id", "name", "course_id", "description", "due_date", "created_at"]:
|
||||
for f in ["id", "name", "course_id", "description", "due_date", "created_at"]:
|
||||
d[f] = getattr(self, f)
|
||||
|
||||
return d
|
||||
|
||||
|
||||
class Content(db.Model):
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
name = sa.Column(sa.String(128), index=True)
|
||||
body = sa.Column(sa.Text, index=True)
|
||||
course_id = sa.Column(sa.ForeignKey(Course.id), index=True)
|
||||
created_at = sa.Column(sa.DateTime)
|
||||
|
||||
def from_dict(self, data) -> None:
|
||||
for field in ["name", "body"]:
|
||||
if field in data:
|
||||
setattr(self, field, data[field])
|
||||
|
||||
if not self.created_at:
|
||||
self.created_at = datetime.now()
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
d = {}
|
||||
for f in ["id", "course_id", "name", "body", "created_at"]:
|
||||
d[f] = getattr(self, f)
|
||||
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user