class Card(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) baujahr = db.Column(db.String) maschinennummer = db.Column(db.Integer) standort = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey( 'users.id')) # foreign key (table name for the User model is "users") author = db.relationship( "User" ) # not a real field, just shows a relationship with the User model machine_id = db.Column( db.Integer, db.ForeignKey("machines.id") ) #One-to-many relationship zwischen vielen Cards und einer Machine machine = db.relationship("Machine") created = db.Column(db.DateTime, default=datetime.utcnow) @classmethod def create(cls, name, baujahr, maschinennummer, standort, author): card = cls(name=name, baujahr=baujahr, maschinennummer=maschinennummer, standort=standort, author=author) db.add(card) db.commit() return card
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship('User') topic_id = db.Column(db.Integer, db.ForeignKey('topics.id')) topic = db.relationship('Topic') created = db.Column(db.DateTime, default=datetime.utcnow) @classmethod def create(cls, text, author, topic): comment = cls(text=text, author=author, topic=topic) db.add(comment) db.commit() if topic.author.email_address: send_email(receiver_email=topic.author.email_address, subject="New comment for your topic!", text="Your topic {} has a new comment.".format( topic.title)) return comment
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) # User foreign key author = db.relationship("User") # User relationship topic_id = db.Column(db.Integer, db.ForeignKey('topics.id')) # Topic foreign key topic = db.relationship("Topic") # Topic relationship created = db.Column(db.DateTime, default=datetime.utcnow) @classmethod def create(cls, text, author, topic): comment = cls(text=text, author=author, topic=topic) db.add(comment) db.commit() # only send of topic author has her/his email in the database if topic.author.email_address: send_email(receiver_email=topic.author.email_address, subject="New comment for your topic!", text="Your topic {} has a new comment.".format( topic.title)) return comment @classmethod def read_all(cls, topic): comments = db.query(Comment).filter_by(topic=topic).all() return comments
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) # User foreign key author = db.relationship("User") # User relationship topic_id = db.Column(db.Integer, db.ForeignKey('topics.id')) # Topic foreign key topic = db.relationship("Topic") # Topic relationship created = db.Column(db.DateTime, default=datetime.utcnow)
class Topic(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship("User") created = db.Column(db.DateTime, default=datetime.utcnow())
class Topic(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship("User") created = db.Column(db.DateTime, default=datetime.now()) @classmethod def create(cls, title, text, author): topic = cls(title=title, text=text, author=author) db.add(topic) db.commit() return topic @classmethod def read(cls, topic_id): topic = db.query(Topic).get(int(topic_id)) return topic @classmethod def update(cls, topic_id, title, text): topic = db.query(Topic).get(int(topic_id)) topic.title = title topic.text = text db.add(topic) db.commit() return topic
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship('User') topic_id = db.Column(db.Integer, db.ForeignKey('topics.id')) topic = db.relationship('Topic') created = db.Column(db.DateTime, default=datetime.utcnow) @classmethod def create(cls, text, author, topic): comment = cls(text=text, author=author, topic=topic) db.add(comment) db.commit() return comment
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship("User") topic_id = db.Column(db.Integer, db.ForeignKey('topics.id')) topic = db.relationship("Topic") created = db.Column(db.DateTime, default=datetime.now()) @classmethod def create(cls, text, author, topic): comment = cls(text=text, author=author, topic=topic) db.add(comment) db.commit() if topic.author.email: send_email(receiver_email=topic.author.email, subject="New comment for your topic!", text="Your topic {} has a new comment.".format( topic.title)) return comment @classmethod def read_all(cls, topic): comments = db.query(Comment).filter_by(topic=topic).all() return comments @classmethod def get_comment(cls, comment_id): comment = db.query(Comment).get(int(comment_id)) return comment
class Topic(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey("users.id")) author = db.relationship("User") created_at = db.Column(db.DateTime, default=datetime.utcnow()) @classmethod def create(cls, title, text, author): topic = cls(title=title, text=text, author=author) db.add(topic) db.commit() return topic
class ProfileData(db.Model): id = db.Column(db.Integer, primary_key=True) firstname = db.Column(db.String) lastname = db.Column(db.String) birthday = db.Column(db.DateTime) owner_id = db.Column(db.Integer, db.ForeignKey('users.id')) owner = db.relationship("User") # age = db.Column(db.Integer) @classmethod def create(cls, firstname, lastname, owner): profile_data = cls(firstname=firstname, lastname=lastname, owner=owner) db.add(profile_data) db.commit() return profile_data
class Topic(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String) text = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey( 'users.id')) # foreign key (table name for the User model is "users") author = db.relationship( "User" ) # not a real field, just shows a relationship with the User model created = db.Column(db.DateTime, default=datetime.utcnow) @classmethod def create(cls, title, text, author): topic = cls(title=title, text=text, author=author) db.add(topic) db.commit() return topic
class Image(db.Model): id = db.Column(db.Integer, primary_key=True) image_url = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship("User") created = db.Column(db.DateTime, default=datetime.utcnow) def insert(self): db.add(self) db.commit() @property def to_dict(self): return { "id": self.id, "image_url": self.image_url, "author": self.author, "created": self.created.strftime('%Y-%m-%d'), }
class Task(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String) day = db.Column(db.String) task_date = db.Column(db.String) full_date = db.Column(db.String) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) author = db.relationship("User") created = db.Column(db.DateTime, default=datetime.utcnow) @classmethod def read(cls, task_id): task = db.query(Task).get(int(task_id)) return task @classmethod def read(cls, task_id): task = db.query(Task).get(int(task_id)) return task