Currently for the different operations we are querying , adding to database and deleting to database directly in the implementation of the routes .
The aim is to add a couple of database methods to add , delete or query the database for the different models.
The different models present are
- userdetails
- education
- experience
- projects
- skills
- achievements
Send your PR with modifications for any one model and also replace with these methods in the routes , do not send for multiple models at a time.
Check Usermodel which has these methods implemented
|
class UserModel(db.Model,UserMixin): |
|
__tablename__= "user" |
|
id = db.Column(db.Integer, primary_key=True) |
|
username = db.Column(db.String(20),unique=True,nullable=False) |
|
email = db.Column(db.String(120),unique=True,nullable=False) |
|
image_file = db.Column(db.String(20),nullable=False,default='default.jpg') |
|
password = db.Column(db.String(60),nullable=False) |
|
#education |
|
education = db.relationship('education',backref='edu',lazy=True) |
|
#experience |
|
experience = db.relationship('experience',backref='exp',lazy=True) |
|
#projects |
|
projects = db.relationship('projects',backref='pro',lazy=True) |
|
#userdetails |
|
userdetails = db.relationship('userdetails',backref='details',lazy=True) |
|
#skills |
|
skills = db.relationship('skills',backref='skill',lazy=True) |
|
#achievements |
|
achievements = db.relationship('achievements',backref='ach',lazy=True) |
|
|
|
def __retr__(self): |
|
return "User {} Email {} Image {}".format(self.username,self.email,self.image_file) |
|
|
|
|
|
def add_to_database(self): |
|
db.session.add(self) |
|
db.session.commit() |
|
|
|
def delete_from_database(self): |
|
db.session.delete(self) |
|
db.session.commit() |
|
|
|
@classmethod |
|
def find_by_username(cls,username): |
|
return cls.query.filter_by(username=username).first() |
|
|
|
@classmethod |
|
def find_by_email(cls,email): |
|
return cls.query.filter_by(email=email).first() |
|
|
|
def reset_token(self,expires_sec=1800): |
|
s = serializer(app.config['SECRET_KEY'],expires_sec) |
|
return s.dumps({"user_id": self.id}).decode("utf-8") |
|
|
|
@staticmethod |
|
def verify_token(token): |
|
s = serializer(app.config['SECRET_KEY']) |
|
try: |
|
user_id = s.loads(token)['user_id'] |
|
except: |
|
return None |
|
return UserModel.query.get(user_id) |
Currently for the different operations we are querying , adding to database and deleting to database directly in the implementation of the routes .
The aim is to add a couple of database methods to add , delete or query the database for the different models.
The different models present are
Send your PR with modifications for any one model and also replace with these methods in the routes , do not send for multiple models at a time.
Check Usermodel which has these methods implemented
Resume-Generator/resume/models.py
Lines 12 to 63 in 97e3b2d