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

  • SEARCH
  • Home
  • 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 9160151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:40:09+00:00 2026-06-17T13:40:09+00:00

I have a Flask application running sqlalachemy. I’m pretty new to sqlalchemy so I’m

  • 0

I have a Flask application running sqlalachemy. I’m pretty new to sqlalchemy so I’m really confused. I’ve made a bunch of classes:

User
Course
Lecture
Note
Queue
Asset

All of which have relationships- Users have many courses, courses have many users, users have many lectures, lectures have many users, users have many notes, notes have many users, courses have many lectures, lectures have many notes, courses have many notes, lecture has a 1 to 1 with queue, a user can have many queues and a queue needs many users, etc etc

So whenever I create a lecture, do I have to instantiate it in all the other things related to it as well?

For example, this is the code I’ve written for making a new lecture

def createLecture(user, course):
    # user and course are existing objects fetched from the db already
    # create new lecture
    newLecture = Lecture()
    db.session.add(newLecture)

    # add lecture to course, add new queue to lecture, add user to queue, add user to lecture
    course.lectures.append(newLecture)
    lecture.users.append(user)
    newQueue = Queue()
    db.session.add(newQueue)
    newQueue.users.append(user)
    newQueue.lecture = newLecture
    db.session.commit()

    return newLecture

This strikes me as ridiculously convoluted and confusing. On top of being confusing, I don’t even know if I covered all of the relationships that I should be making (it’s easy to forget one with so many).

There has to be some better way to add a new object when it’s tied to many other objects with various relationships.

How can I be more organized?

  • 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-06-17T13:40:10+00:00Added an answer on June 17, 2026 at 1:40 pm

    Since this was a complex database schema, I double checked every relationship and made sure it was specified correctly.

    In examining my schema, I figured that some relationships can be fulfilled when the object is instantiated, and that is the best way to reduce code messiness.

    So my example from above is written as:

    def createLecture(user, course):
    # create new lecture
    now = datetime.now()
    dt = now.strftime("%Y-%m-%d-%H-%M")
    newLecture = Lecture(dt, course)
    db.session.add(newLecture)
    
    # add lecture to course, add new queue to lecture, add user to queue, add new user to lecture
    newQueue = Queue(newLecture)
    db.session.add(newQueue)
    newLecture.users.append(user)
    newQueue.users.append(user)
    newLecture.groupID = pad.createGroupIfNotExistsFor(newLecture.course.name+dt)['groupID']
    
    db.session.commit()
    return newLecture
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application written in Python using Flask. Right now I'm running
I have a Flask web application running behind gunicorn and Nginx. Nginx proxies any
I have a web application which is deployed by the means of Flask. I'm
I have made a flash application and in this flash application I have included
I have flash (AIR) application running on a single controlled system (there is only
I have Chrome running a flash game and Firefox running another Flash application. When
I have a weird error in my flask application. Problem is that the code
I am trying to get a flask application running on an Apache server (2.2.15)
So I have created a flask application in OS from the OS quickstart on
I've made a website using Flask and I have no problems getting things to

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.