Course content #72
@@ -120,3 +120,26 @@ class Assignment(db.Model):
|
|||||||
d[f] = getattr(self, f)
|
d[f] = getattr(self, f)
|
||||||
|
|
||||||
return d
|
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
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
"""Create content model
|
||||||
|
|
||||||
|
Revision ID: c62aec1c6b91
|
||||||
|
Revises: 1e88e783d238
|
||||||
|
Create Date: 2023-04-14 16:46:43.513842
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'c62aec1c6b91'
|
||||||
|
down_revision = '1e88e783d238'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('content',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=128), nullable=True),
|
||||||
|
sa.Column('body', sa.Text(), nullable=True),
|
||||||
|
sa.Column('course_id', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('content', schema=None) as batch_op:
|
||||||
|
batch_op.create_index(batch_op.f('ix_content_body'), ['body'], unique=False)
|
||||||
|
batch_op.create_index(batch_op.f('ix_content_course_id'), ['course_id'], unique=False)
|
||||||
|
batch_op.create_index(batch_op.f('ix_content_name'), ['name'], unique=False)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('content', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index(batch_op.f('ix_content_name'))
|
||||||
|
batch_op.drop_index(batch_op.f('ix_content_course_id'))
|
||||||
|
batch_op.drop_index(batch_op.f('ix_content_body'))
|
||||||
|
|
||||||
|
op.drop_table('content')
|
||||||
|
# ### end Alembic commands ###
|
||||||
Reference in New Issue
Block a user