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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:11:51+00:00 2026-05-28T00:11:51+00:00

I have my two class in two separate files, customer and address. Address is

  • 0

I have my two class in two separate files, customer and address. Address is going to be used in other places for instance vendors have addresses. The customer class needs to reference the address class in three ways. A customer has a default ship to address (one to one) a default bill to address (one to one) and his a list of multiple addresses that can be selected if the defaults aren’t needed.
The customer class in the ar.py file and the address class is in the global.py file.

The one to ones just work but the one to many list I can’t figure out how to make it work with the classes in two different files. With out circular issues.

Thanks for any insights you can provide …

globals.py
from erp.model import DeclarativeBase, metadata, DBSession

class Address(DeclarativeBase):
    __tablename__ = 'addresses'
    address_id = Column(Integer,primary_key=True)
    name = Column(Unicode(100))
    address_one = Column(Unicode(100))
    address_two = Column(Unicode(100))
    address_three = Column(Unicode(100))
    city = Column(Unicode(100))
    state = Column(Unicode(100))
    zip_code = Column(Unicode(100))
    phone = Column(Unicode(100))
    fax = Column(Unicode(100))
    contact = Column(Unicode(100))

ar.py ...
from erp.model.globals import Address

class Customer(DeclarativeBase):
    __tablename__ = 'customers'
    customer_id = Column(Integer, primary_key=True)
    customer_name = Column(Unicode(100))
    discount = Column(Float)
    #bill_to_id = Column(Integer, ForeignKey('addresses.address_id'))
    #bill_to = relation(Address,primaryjoin=bill_to_id==Address.address_id,uselist=False)
    ship_to_id = Column(Integer, ForeignKey('addresses.address_id'))
    ship_to = relation(Address,primaryjoin=ship_to_id==Address.address_id,uselist=False)
    locations = relation(Address,backref="customer",primaryjoin='customers.customer_id'=='addresses.customer_id')

I can make this work just fine if i have everything in one file however this over complicates the project layout with having a bunch of stuff in one file or worse duplication the same kind of layout of class address in the ar file and also in the vendor file.

Again thanks for your help!
Paul

  • 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-28T00:11:51+00:00Added an answer on May 28, 2026 at 12:11 am

    You can create models using strings instead of instances. For example

    ship_to = relation('Address', ...)
    

    SQLAlchemy will handle turning these into objects.

    A one to many is typically handled via a fkey on addresses pointing back to the customers. However this won’t work well if you are using the addresses for multiple purposes. If you want all of the addresses in your database to be stored in a single table, then I’d suggest adding link tables between each table and addresses. For example customer_addresses would have fkeys to addresses and customers. The other option is to make a separate table for customer_addresses vs vendor_addresses. If you’d like to do this the best way would be to create an AddressMixin which you could apply to different objects:

    class AddressMixin(object):
        @declared_attr
        def street(cls):
            return Column(Text, ...)
    
    class CustomerAddress(Base, AddressMixin):
        __tablename__ = 'customer_addresses'
        id = ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two separate classes, A and B. I also have Repository class
My app uses two databases (separate files). To handle these databases I have created
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to
I have two classes class A { public string something { get; set; }
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
i have two models: class Category has many :jobs end class Job belongs_to :category
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
here is what my code looks like i have two forms: class Form_1 extends
I'm not very good in SQL and HQL... I have two domains: class Hotel
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;

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.