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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:19:00+00:00 2026-06-13T20:19:00+00:00

I have a very simple User class definition: class User(Base): implements(interfaces.IUser) __tablename__ = ‘users’

  • 0

I have a very simple User class definition:

class User(Base):
    implements(interfaces.IUser)
    __tablename__ = 'users'
    #Fields description
    id = Column(Integer, primary_key=True)

    client_id = Column(Integer, ForeignKey('w2_client.id'))
    client = relationship("Client", backref=backref('users', order_by=id))

I want to generate automatically a GUI to edit the object User (and other type of class). So I need to get all the meta data of the table, for example, I can do:

    for c in User.__table__.columns:
        print c.name, c.type, c.nullable, c.primary_key, c.foreign_keys

But I can not get any information about the relationship “client”, the c.foreign_keys just shows me the table related to the foreign_keys but not the attribute “client” I’ve defined.
Please let me know if my question is not clear

  • 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-13T20:19:02+00:00Added an answer on June 13, 2026 at 8:19 pm

    It’s true that is not readily available. I had to come up with my own function after some reverse-engineering.

    Here is the metadata that I use. I little different than what you are are looking for, but perhaps you can use it.

    # structure returned by get_metadata function.
    MetaDataTuple = collections.namedtuple("MetaDataTuple",
            "coltype, colname, default, m2m, nullable, uselist, collection")
    
    
    def get_metadata_iterator(class_):
        for prop in class_mapper(class_).iterate_properties:
            name = prop.key
            if name.startswith("_") or name == "id" or name.endswith("_id"):
                continue
            md = _get_column_metadata(prop)
            if md is None:
                continue
            yield md
    
    
    def get_column_metadata(class_, colname):
        prop = class_mapper(class_).get_property(colname)
        md = _get_column_metadata(prop)
        if md is None:
            raise ValueError("Not a column name: %r." % (colname,))
        return md
    
    
    def _get_column_metadata(prop):
        name = prop.key
        m2m = False
        default = None
        nullable = None
        uselist = False
        collection = None
        proptype = type(prop)
        if proptype is ColumnProperty:
            coltype = type(prop.columns[0].type).__name__
            try:
                default = prop.columns[0].default
            except AttributeError:
                default = None
            else:
                if default is not None:
                    default = default.arg(None)
            nullable = prop.columns[0].nullable
        elif proptype is RelationshipProperty:
            coltype = RelationshipProperty.__name__
            m2m = prop.secondary is not None
            nullable = prop.local_side[0].nullable
            uselist = prop.uselist
            if prop.collection_class is not None:
                collection = type(prop.collection_class()).__name__
            else:
                collection = "list"
        else:
            return None
        return MetaDataTuple(coltype, str(name), default, m2m, nullable, uselist, collection)
    
    
    def get_metadata(class_):
        """Returns a list of MetaDataTuple structures.
        """
        return list(get_metadata_iterator(class_))
    
    
    def get_metadata_map(class_):
        rv = {}
        for metadata in get_metadata_iterator(class_):
            rv[metadata.colname] = metadata
        return rv
    

    But it doesn’t have the primary key. I use a separate function for that.

    mapper = class_mapper(ORMClass)
    pkname = str(mapper.primary_key[0].name)
    

    Perhaps I should put the primary key name in the metadata.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,
I have the following very simple class which looks for the last known user
This is driving me crazy. I have a very simple user control: public int?
FOUND THE ANSWER MYSELF, see below... I'd like to have a very simple user
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have a very simple page with which a user uploads a file. Using
I have created a very simple user control ActiveX with a simple button that
I have written the following very simple Java program to ask user enter a
I have a class that is meant to be a very simple in-game level
Given a very simple object: class User { private Integer id; private String name;

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.