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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:48:23+00:00 2026-05-31T03:48:23+00:00

Is it correct, that in Web2Py you are not able to create custom methods

  • 0

Is it correct, that in Web2Py you are not able to create custom methods within “models”, so that they could contain business logic you want models to implement?

In case of Django you can just do something like:

class Aircraft(models.Model):
    '''I am an aircraft. I can fly, if I am created in Django.
    '''
    name = models.CharField(max_length=20)
    def fly(self):
        # ... some advanced logic here ...
        return 'I am flying'

But is it possible to do something like that (create custom methods) in Web2Py without the need to write the whole ORM system from the beginning or to share single method between instances of all the tables? Is there any established way to do that? For example:

db.define_table("aircrafts",
    Field("name", type="string", length=20)
)

aircraft = db(db.aircrafts).select().first()

# I am an aircraft too, please make me fly
aircraft.fly()
  • 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-31T03:48:24+00:00Added an answer on May 31, 2026 at 3:48 am

    Yes, you can define virtual fields:

    db.aircrafts.fly = Field.Virtual(lambda row: 'I am flying')
    aircraft = db(db.aircrafts).select().first() 
    print aircraft.fly
    

    or

    db.aircrafts.fly = Field.Lazy(lambda row: 'I am flying')
    aircraft = db(db.aircrafts).select().first() 
    print aircraft.fly()
    

    In the first example above, the “fly” value is automatically calculated for all records when they are selected. In the second example, the calculation is lazy and only executed when .fly() is actually called on a specific record.

    You can also do this with old style virtual fields, which may be better for complex functions.

    Note, this is handled differently from Django because web2py uses a database abstraction layer (DAL) rather than an ORM. Tables are not modeled as custom classes but as instances of the DAL Table class.

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

Sidebar

Related Questions

Is it correct to assume that JQuery is not actually an implementation of ECMA
That's my code but that says not well formed. How can I correct that?
Is it correct that one can create spring beans using just the @Component annotation
Is is correct that jqGrid doesn't currently contain an inline add. I'm trying to
Is it correct that the reveal applescript command is broken with iTunes 9? Works:
I'm new to Symfony. Is my understanding correct that the User class is actually
(1). When using C++ template, is it correct that the compiler (e.g. g++) will
My Visual Studio 2008 debugger is showing integers as hexadecimals, how to correct that?
Like in: u'Hello' My guess is that it indicates "Unicode", is that correct? If
Am I correct in assuming that the only difference between "windows files" and "unix

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.