Skip to content

Instantly share code, notes, and snippets.

@Kd-Here
Created March 4, 2023 19:44
Show Gist options
  • Save Kd-Here/fbed9227624f8393bc54db0096a9dad0 to your computer and use it in GitHub Desktop.
Save Kd-Here/fbed9227624f8393bc54db0096a9dad0 to your computer and use it in GitHub Desktop.
In this example, we define a User class that inherits from db.Model, which is a SQLAlchemy base class. We define several columns in the class, each of which maps to a column in the database table. The id column is a primary key, which is required for each table. The email column is unique and cannot be null, while the password, first_name, and l…
from . import db #i.e. same from website import db ( . means current and we had __init__.py which is used for package )
from flask_login import UserMixin
from sqlalchemy.sql import func
# This is schema for user made notes
# This is schema for User details
class User(db.Model,UserMixin):
"""
User is database storing all details of user so we have class called user that stores schema,
UserMixin is used bcoz we already used login package of flask that helps in creating login application so for storing we used Mixin
"""
id = db.Column(db.Integer,primary_key = True)
email = db.Column(db.String(150),unique = True)
password = db.Column(db.String(150))
first_name = db.Column(db.String(150))
notes = db.relationship("Note")
"""Like Foreign key we don't need to put Note here in lower bcoz sqlalchemy is
following different logic for relationship"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment