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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:47:06+00:00 2026-06-06T15:47:06+00:00

I see lots of apps using Form objects to validate data and then passing

  • 0

I see lots of apps using Form objects to validate data and then passing the data to the model, while putting absolutely no validation in the model. I feel it’s better to put core validation in the model itself (e.g., no users under the age of 18, ever) to be run regardless of the context. In other words, I don’t care how the user is being created (whether through web ui or command line), the core rules should always apply.

I’m using SQLAlchemy (within a Pyramid application), and I would like to define my core validation rules within the model in a way that my forms (WTForms) always respect the core rules defined in the model so that all data is consistent.

Is anybody else already doing this, or something similar?

Something similar to this php solution.

  • 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-06T15:47:07+00:00Added an answer on June 6, 2026 at 3:47 pm

    SQLAlchemy allows you to register listeners, which are invoked when certain events occur, for example you can register an event to be triggered when a model’s field is modified. From SQLAlchemy documentation:

    Listeners have the option to return a possibly modified version of the
    value, when the retval=True flag is passed to listen():

    def validate_phone(target, value, oldvalue, initiator):
        "Strip non-numeric characters from a phone number"
    
        return re.sub(r'(?![0-9])', '', value)
    
    # setup listener on UserContact.phone attribute, instructing
    # it to use the return value 
    listen(UserContact.phone, 'set', validate_phone, retval=True)
    

    A validation function like the above can also raise an exception such
    as ValueError to halt the operation.

    So, as you see, you can either modify or reject values for certain field at the model level.

    I’m not sure if your form library integrates with this feature, but it definitely should not be too difficult to roll your own solution.

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

Sidebar

Related Questions

I see lots of jquery tutorials from building the submit form from scratch, and
I'm using jquery, ajax, & .net to call a method. I see lots of
I see lots of articles saying how great IoC and DI are and none
I see a lots a answer about this problem but my is a little
(see title) here is the code, I'm using ms command prompt (irb) to do
I see lots of sites that show how to set it, but I just
I see lots of : map.root :controller => home Its I know simple, but
I see lots of php libraries that can parse html. A nice example is
I see lots of examples and man pages on how to do things like
So I look at C++/Tk for as a GUI library. I see lots of

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.