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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:44:35+00:00 2026-05-25T13:44:35+00:00

I have a problem when i try to create new model field type –

  • 0

I have a problem when i try to create new model field type – postgres time[].

Thanks to psycopg2 the information from database is ready out and converted into python list.

the list looks like that thought:

[[datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)], [datetime.time(0, 0), datetime.time(23, 59, 59)]]

Now i could create widget, that uses JavaScript to convert it into time. But it seems to me, that it could be done faster on python side and since all kinds of time picker widgets deal with time in %H:%M:%S format it looks wise to both get and give data in same format. Converting data back to string, which is ‘datetime.time(0, 0)’ does not look very nice either.

so, all that brings me to asking – what kind of method of django.db.models.fields.Field class is called after database read? from https://docs.djangoproject.com/en/dev/howto/custom-model-fields/ it looks like it should be Field.to_python, but when i add method like:

def to_python(self, value):
    return 'xxx'

to my field, then i still see previously added list of datetimes in my input not ‘xxx’

Can someone help me sort this out please 🙂

Alan

  • 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-25T13:44:35+00:00Added an answer on May 25, 2026 at 1:44 pm

    After digging around in the web i found a solution – signals.

    outside of class scope:

    def loads(value)
        #do value conversion here
    

    inside field scope

    def contribute_to_class(self, cls, name):
        super(MyFieldName, self).contribute_to_class(cls, name)
        signals.post_init.connect(self.post_init, cls, True)
    
    def post_init(self, **kwargs):
        instance = kwargs['instance']
        value = self.value_from_object(instance)
        if value:
            setattr(instance, self.attname, str(loads(value)))
        else:
            setattr(instance, self.attname, None)
    

    Basically thats it.

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

Sidebar

Related Questions

I want to create user profile with image. That user can upload his photo,
REVISED BUT SAME ISSUE: I am building a site with MVC 3 and have
Couldn't find Submission without an ID This problem has haunted me for last few
We have a form and depending upon the circumstances we want to switch between
Background I, like scores of programmers before me, am working on an application that
I'm currently working on a system that is using handlebars.js template's. It's working for
I am using this article to make a one-to-one relationship between my two objects
I got a little ruby app going and I'm having trouble with one part.
I started the question differently, about a collection_select, but I found out that is

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.