Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:34:42+00:00 2026-05-23T21:34:42+00:00

Using Flask Flask-sqlalchemy Sqlalchemy Jquery Datatables (jquery plugin) Jeditable (jquery plugin) Consider this user

  • 0

Using

  • Flask
  • Flask-sqlalchemy
  • Sqlalchemy
  • Jquery
  • Datatables (jquery plugin)
  • Jeditable (jquery plugin)

Consider this user class ( straight out of flask-sqlalchemy docs):

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)

    def __init__(self, username, email):
        self.username = username
        self.email = email

    def __repr__(self):
        return '<User %r>' % self.username

The datatables makes an ajax request and populates the table. Each td then is made editable in place with jeditable. As soon as a td is modified, jeditable makes a POST request to localhost/modify containing:

  • The row id(the same id from the user class)
  • The new modified value
  • The column of the table that was altered ( for the sake of argument let’s assume that there are three columns id/username/email) (int)

Now, i’d like that in the function that handles localhost/modify i take the row id, make a user object and query the db for that specific row, see what property needs to be modified, modify it with the new value and commit to the db. Here’s what i got so far:

@app.route('/modify', methods=['GET', 'POST'])
def modify()
    if request.method == 'POST' :
        user = user.query.get(form.row_id)
        if form.column_id == int(0):
            user.id = form.value
        elif form.column_id == int(1):
            user.username = form.value
        elif form.column_id == int(2):
            user.email = form.value
        else:
            pass
        db.session.commit()
    return 'ok'

This way, yes it does work but theremust be amore beautiful approach. This one doesn’t seem very…pythonic

Mihai

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:34:42+00:00Added an answer on May 23, 2026 at 9:34 pm

    Use a map of column ID to attribute name.

    colmap = {
        0: 'id',
        1: 'username',
        2: 'email',
    }
    
    @app.route('/modify', methods=['GET', 'POST'])
    def modify()
        if request.method == 'POST' :
            user = user.query.get(form.row_id)
            try:
                setattr(user, colmap[form.column_id], form.value)
            except KeyError:
                pass
            db.session.commit()
        return 'ok'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying out the Flaskr tutorial(http://flask.pocoo.org/docs/) and I got the following error after I
I've made a website using Flask and I have no problems getting things to
I'm a Flask beginner and I want to build a poll app using flask
I'm using Jinja2's nl2br filter, which looks like: import re from jinja2 import environmentfilter,
Has anyone tried using flash media server 4 on Amazon web service? I was
until now I was using flash based swfupload and its swfupload.js which provides users
i'm building a website using flash. i have a external swf file that i
I'm trying to make a facebook sort of social networking site (not a facebook
I have a application written in Twisted and I want to add a web
I have a page that displays a list of files in a directory. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.