0

I have an issue trying to get 'usernames' column from a database filtering on the logged-in user. Filtering on the logged-in user works, but not the "please don't get me anything else than what is in the column username where the userID is x"

The flask code that runs:

from flask import Blueprint, render_template
from flask_login import login_required, current_user
from flask import Blueprint, redirect, render_template, url_for, request, flash
from .models import Logins, Users
from .security import encrypt, decrypt
from . import db

viewlogins = Blueprint('viewlogins', __name__)

@viewlogins.route('/viewlogins')
@login_required
def viewlogin():
    username=Logins.query.filter_by(userID=current_user.id and column.username).all()
    return render_template('viewlogins.html',name=current_user.name, login=username)

and the model script:

from flask_login import UserMixin
from sqlalchemy import ForeignKey
from . import db

class Logins(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    location = db.Column(db.String(100))
    username = db.Column(db.String(100))
    password = db.Column(db.String(255))
    url = db.Column(db.String(255))
    note = db.Column(db.String(1000))
    userID = db.Column(db.Integer, ForeignKey('users.id'))

tldr: please help me make this line work in flask-sqlalchemy with model script

SELECT username FROM Logins WHERE userID IS x
1
  • So you want to specify the column that you ate getting? Example only get the username column? Commented Apr 27, 2022 at 21:52

1 Answer 1

0

To select columns to be included on the query result you could add with_entities

Logins.query.with_entities(Logins.username).filter(Logins.userID == x).all()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.