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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:06:13+00:00 2026-05-22T20:06:13+00:00

I create a table in database using sqlalchemy and now want to make a

  • 0

I create a table in database using sqlalchemy and now want to make a form according to the database using django and valid it use formencode. (mention I use Django Web Framework)
The python code is below

from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('mysql+mysqldb://root:@localhost/testdb', echo = True)

metadata = MetaData(engine)

session = create_session()

one_table = Table('one', metadata,
              Column('id',Integer, primary_key = True),
              Column('name',String(40))
              )
many_table = Table('many_i', metadata,
               Column('id', Integer, primary_key = True),
               Column('name', String(40)),
               Column('one_id',Integer, ForeignKey('one.id'))
               )

metadata.create_all(engine)

class One(object):
def __init__(self, name):
    self.name = name
def __repr__(self):
    return self.name
#pass

class Man_i(object):
def __init__(self, name):
   self.name = name

def __repr__(self):
    return self.name
#pass

mapper(One, one_table,
   properties={'o2m':relationship(Man_i)
               }
   )

mapper(Man_i, many_table)
  • 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-22T20:06:14+00:00Added an answer on May 22, 2026 at 8:06 pm

    At last I crete my own solutions can any one prefer me better than this
    **and if any one want they can use it its really save data onto database (not comment this line from settings.py->middleware_classes ->> #’django.middleware.csrf.CsrfViewMiddleware’, for using post method )**

    from django.shortcuts import render_to_response
    
    from sqlalchemy import *
    from sqlalchemy.orm import *
    
    import formencode
    from formencode import validators, htmlfill
    
    engine = create_engine("mysql+mysqldb://root:@localhost/testdb",echo = True)
    #create database link
    
    metadata = MetaData(engine)
    session = create_session()
    
    #database table 
    person_table = Table('person', metadata,
                         Column('id', Integer, primary_key = True),
                         Column('name', String(40)),
                         Column('age', Integer),
                         Column('about', String(100))
                         )
    
    metadata.create_all(engine)#create database if not exist
    
    class Person(object):#create a class for mapping
        def __init__(self,name,age,about):
            self.name = name
            self.age = age
            self.about = about
        def __repr__(self):
            return self.name, self.age, self.about
    
    mapper(Person, person_table) #define map
    
    class PersonValid(formencode.Schema):#for validation
        name = validators.String(not_empty=True, min = 3, max = 40)
        age = validators.Int(not_empty = True, min=1, max=120)
        about = validators.String(not_empty=True, min = 5, max = 100)
    
    
    def insert_d(request): #insert def
    
     #for template page
        out = """
    
        <table>
          <tr>
          <td>Name:</td>
          <td><input type="text" name = "name"/>
          <form:error name = "name"/>
          <!--form:iferror name="name">Horrible horror message</form:iferror-->
          <td>
          </tr>
          <tr>
          <td>Age:</td>
          <td><input type="text" name="age"/>
          <form:error name="age" />
          <!--form:iferror name="age">Horrible horror message</form:iferror-->
          </td>
          </tr>
          <tr>
          <td>About</td>
          <td><textarea name="about"></textarea>
          <form:error name="about" />
          <!--form:iferror name="about">Horrible horror message</form:iferror-->
          <td>
          </tr>
          <table>
          <input type = "submit" value = "Submit">
    
        """
    
        if request.method == 'POST':
            inp = {'name': request.POST['name'],
                   'age': request.POST['age'],
                   'about': request.POST['about']
                   }
            try:
                PersonValid.to_python(inp)
    
                a_person = Person(['name'],
                                  inp['age'],
                                  inp['about']
                                  )
    
                session.add(a_person)
                session.flush()
                return render_to_response('formencode/htmlfill.html',
                                          {'out': htmlfill.render(out,{} ),
                                           'text':"Saved OK"}
                                          )
    
    
            except validators.Invalid, e:
    
                val = htmlfill.render(out, e.error_dict or {})
    
        else:
            return render_to_response('formencode/htmlfill.html',
                                      {'out':out,'text':"POST NOT START"}
                                      )
    
    
        #html form
    
        #the htmlfill.html locate in "templete/formencode/" 
         directory contain the page below
    
    <form name="out" method="POST" action="/fcode_alch/">
    
    {%autoescape off%}    
    {{text}}
    {{out}}    
    {%endautoescape%}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new row in my database on a table that
I access a a postgres table using SQLAlchemy. I want a query to have
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have implemented a linked list as a self-referencing database table: CREATE TABLE LinkedList(
I need to create a database table to store different changelog/auditing (when something was
I inherited MYSQL database that has lots of tables with data like CREATE TABLE
I have an Access database in which I drop the table and then create
When designing a database to use MVCC (Multi-Version Concurrency Control), you create tables with
I'm using Elixir in a project that connects to a postgres database. I want
I am writing a multimedia archive database backend and I want to use joined

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.