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 6898233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:16:11+00:00 2026-05-27T07:16:11+00:00

How do you insert a record with one to many relationship in Python Elixir?

  • 0

How do you insert a record with one to many relationship in Python Elixir? See code below.

from elixir import *    

class Product(Entity):
    using_options(shortnames=True)
    name = Field(Unicode)
    category = ManyToOne('Category')
    brand = ManyToOne('Brand')
    barcode = Field(String)
    cost = Field(Float)
    price = Field(Float)
    order_quantity = Field(Float)
    unit = Field(Unicode)



class Category(Entity):
    using_options(shortnames=True)
    name = Field(Unicode)
    product = OneToMany('Product')

def main():
    metadata.bind = 'sqlite:///pypos.sqlite'
    metadata.bind.echo = False
    setup_all()
    create_all()

   Brand(name='Asrock')
   Brand(name='Asus')
   Category(name='Motherboard')
   Category(name='Processor')     
   session.commit()

   p = Product(name='N98', cost=2100.50, price=2500.50, order_quantity=5, unit='unit')

   '''
   How do you add a Category and a Brand on the Product table?
   Is there a lookup for this?
   '''
   #Is there an alternative to this two instruction?
   p.category = Category(name='Motherboard')
   p.brand = Brand(name='Asrock')

  session.commit()

if__name__=='__main__': main()   
  • 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-27T07:16:12+00:00Added an answer on May 27, 2026 at 7:16 am

    just figured it out. Its…

    asrock = Brand(name='Asrock')
    asus = Brand(name='Asus')
    mobo = Category(name='Motherboard')
    proc = Category(name='Processor')     
    session.commit()
    
    p1 = Product(name='N98', cost=2100.50, price=2500.50, order_quantity=5, unit='unit',    
        category=mobo, brand=asrock)
    
    p2 = Product(name='M-N98', cost=2300.50, price=2500.50, order_quantity=5, unit='unit',    
        category=mobo, brand=asus)
    
    session.commit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me, How to insert one record in SQL Server by using
I have read many article about this one. I want to hear from you.
I have 2 tables (Item and Code) with relation one to many(one Item can
A] Summary: Using get or insert functionality on one to many django models, checking
Say I have a one-to-many relationship between clients and addresses. Clients can have multiple
I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.
I have two tables with a many-to-one relationship. (Oracle) **Table: PARENT** Field: A (PK)
I am trying to insert a record into a table using Linq but get
I'm using PDO to insert a record (mysql and php) $stmt->bindParam(':field1', $field1, PDO::PARAM_STR); $stmt->bindParam(':field2',
I'm using an SqlCommand object to insert a record into a table with an

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.