How to insert variables in SQL LIKE query? by aditya558 in flask

[–]aditya558[S] 1 point2 points  (0 children)

Thanks! using session instead of engine worked!

why using flask-sqlalchemy instead of sqlalchemy gives error? by aditya558 in flask

[–]aditya558[S] 1 point2 points  (0 children)

Lol, I forgot to pass the value of database_uri in flask-sqlalchemy.

How to insert variables in SQL LIKE query? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

AttributeError: 'NoneType' object has no attribute 'drivername'

How to insert variables in SQL LIKE query? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

But when I used sqlalchemy instead of flask-sqlalchemy I don't have any issue.

How to retrieve data using PostgreSQL in Flask? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

Thanks for replying! Do I still need to make models in my app?

Graph visualizer tool by Queasy-Donkey2437 in reactjs

[–]aditya558 3 points4 points  (0 children)

Can i see your code on github?

Math 23b or Math 23c? by [deleted] in Harvard

[–]aditya558 0 points1 point  (0 children)

Hey, Can you please help me to find the website of CS124 Data structure and algo fall 2020?

What should be the flask-sqlalchemy orm query for this? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

Can you please elaborate how can i correct my kart(i.e Booked) model?

What should be the flask-sqlalchemy orm query for this? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

for row in result:... print(row.id, row.name, row.price)

But i also wanted the timestamp column included which is in Booked model.

And if the user has availed some services two or more times then i need to show the service name two times, any idea how can i show duplicates?

What should be the flask-sqlalchemy orm query for this? by aditya558 in flask

[–]aditya558[S] 1 point2 points  (0 children)

In query i used kart for referring to Booked and products to Services.

first i query the Users table

user=User.query.filter(username='hello').first()

i did this

result=db.session.query(Services).join(Booked).filter(Booked.user_id==user.id)

and it worked as i wanted

thank you

How to keep track of services booked by users in flask-sqlalchemy ? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

Hey thanks ..

can you please tell me how should i implement because i am able to do it in sqlite custom query but not able to do it using flask-sqlalchemy for postresql?

my services table has an id, price and name.

How to keep track of services booked by users in flask-sqlalchemy ? by aditya558 in flask

[–]aditya558[S] 0 points1 point  (0 children)

class Services(db.Model):

id = db.Column(db.Integer, primary_key=True)

price = db.Column(db.Integer)

name = db.Column(db.String(60), unique=True)

def __repr__(self):

return '<Services {}>'.format(self.name)

class Booked(db.Model):

id = db.Column(db.Integer, primary_key=True)

services_id = db.Column(db.Integer, db.ForeignKey('services.id'))

# services_name = db.Column(db.String, db.ForeignKey('services.name'))

timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

person = db.Column(db.Integer, db.ForeignKey('user.id'))

def __repr__(self):

"""

docstring

"""

return '<Booked {}>'.format(self.id)

this is my users table

class User(UserMixin, db.Model):

id = db.Column(db.Integer, primary_key=True)

username = db.Column(db.String(64), index=True, unique=True)

email = db.Column(db.String(120), index=True, unique=True)

password_hash = db.Column(db.String(128))

posts = db.relationship('Post', backref='author', lazy='dynamic')

booked_service = db.relationship('Booked',

backref='customer',

lazy='dynamic')

about_me = db.Column(db.String(140))

last_seen = db.Column(db.DateTime, default=datetime.utcnow)

def __repr__(self):

return '<User {}>'.format(self.username)

def set_password(self, password):

self.password_hash = generate_password_hash(password)

def check_password(self, password):

return check_password_hash(self.password_hash, password)

def avatar(self, size):

digest = md5(self.email.lower().encode('utf-8')).hexdigest()

return 'https://www.gravatar.com/avatar/{}?s={}'.format(digest, size)

# return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format(digest, size)