programmeerles-ouderen

Teach programming to seniors
Log | Files | Refs

commit 37797f037cdaed16b6e70fe3a9970c3ded977804
parent ba6b02b1c87a2a43bc99de634e696f456081c2a2
Author: Friedel Schön <[email protected]>
Date:   Thu,  7 Apr 2022 15:09:17 +0200

new db

Diffstat:
Mpgmles/models.py | 26++++++++++++--------------
Mpgmles/routes.py | 15+++++++++------
2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/pgmles/models.py b/pgmles/models.py @@ -23,28 +23,26 @@ class User(db.Model, UserMixin): return f"User('{self.username}', '{self.email}', '{self.image_file}')" -class Language(db.Model): +class Course(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) - info = db.Column(db.Text) - - def __repr__(self): - return f"Language('{self.name}', '{self.info}')" - - -class Classes(db.Model): - id = db.Column(db.Integer, primary_key=True) - user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) - language_id = db.Column(db.Integer, db.ForeignKey( - 'language.id'), nullable=False) + description = db.Column(db.Text, nullable=False) teacher_id = db.Column( db.Integer, db.ForeignKey('user.id'), nullable=False) - start = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) + weekday = db.Column(db.Integer, nullable=False) + start = db.Column(db.String(10), nullable=False, default=datetime.utcnow) + end = db.Column(db.String(10), nullable=False, default=datetime.utcnow) location = db.Column(db.String(120), nullable=False) def __repr__(self): - return f"Language('{self.id}', '{self.language_id}', '{self.start}', '{self.location}')" + return f"Course('{self.id}', '{self.name}', '{self.description}')" + +class CourseMember(db.Model): + id = db.Column(db.Integer, primary_key=True) + course_id = db.Column(db.Integer, db.ForeignKey( + 'course.id'), nullable=False) + user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) # date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # content = db.Column(db.Text, nullable=False) diff --git a/pgmles/routes.py b/pgmles/routes.py @@ -7,17 +7,20 @@ from PIL import Image from . import app, bcrypt, calendar, db from .forms import LoginForm, PostForm, RegistrationForm, UpdateAccountForm -from .models import Classes, Language, User +from .models import Course, CourseMember, User @app.route("/") def index(): - languages = Language.query.all() - lijst = [] + courses = Course.query.all() + subscriptions = [] if current_user.is_authenticated: - subs = Classes.query.filter_by(user_id=current_user.id) - lijst = [sub.language_id for sub in subs] - return render_template('index.html', calendar=calendar, languages=languages, subs=lijst, subscribed="subscribed") + members = CourseMember.query.filter_by(user_id=current_user.id) + subscriptions = [Course.query.filter_by( + id=cm.course_id) for cm in members] +# for coursemember in members: +# course = Course + return render_template('index.html', calendar=calendar, courses=courses, subs=subscriptions, subscribed="subscribed") @app.route("/about")