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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:24:33+00:00 2026-06-07T14:24:33+00:00

I have a model of the form: class MyModel(base): # … datetime = Column(DateTime)

  • 0

I have a model of the form:

class MyModel(base):
    # ...
    datetime = Column(DateTime)
    # ...

and would like to create a .date and a .time property which correspond to the .datetime column. The SQLA documentations shows a couple of examples of combining properties (such as firstname + lastname => fullname) but nothing for decomposing.

I think using @hybrid_property and friends I can do the initial decomposition but am unsure about assignment (so if n = MyModel.query...one() I wish to be able to do n.date = d and have it update the .datetime field.)

My primary RDBMS is MySQL.

(For those that are interested in my motivation for wanting to do this: I have a lot of client-side code which is duck-typed to expect .date and .time fields however many stored procedures and triggers on the server expect a single .datetime column.)

  • 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-07T14:24:34+00:00Added an answer on June 7, 2026 at 2:24 pm

    The docs say explicitly that you can do this, you need to use the @hybrid.property and @value.setter decorators and your own code to return the date or time in the expected format:

    from sqlalchemy.ext.hybrid import hybrid_property
    
    class SomeClass(object):
        @hybrid_property
        def value(self):
            return self._value
    
        @value.setter
        def value(self, value):
            self._value = value
    

    Full disclosure: I have used the property feature but not the setter feature.

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

Sidebar

Related Questions

I have a Model that looks like: class MyModel(Model): name = models.TextField(blank=True, default='') bio
my model looks like this: class MyModel(models.Model): field1 = models.FloatField(default=0) field2 = models.FloatField(default=0) This
I created a form class based on a model: class MyModel(models.Model): increasing_field = models.PositiveIntegerField()
I have a model: class MyModel(models.Model): field_1 = models.ForeignKey(FirstModel) field_2 = models.ForeignKey(SecondModel) And I
Hi I have a model containing: class MyModel(models.Model): id = models.IntegerField(primary_key=True) recorded_on = models.DateField()
Adapted from the nested form Railscast , I have: In my model class Post
I have this in my model: class Person < ActiveRecord::Base RELATIONSHIP_STATUSES = [ single,
Using PlayFramework 2.0.1, I have a model : class MyModel extends Model { @Constraints.Required
I have a model form that contains a DecimalField() with max_digits set to 5.
I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id

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.