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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:00:25+00:00 2026-06-07T07:00:25+00:00

I have modeled a class called ConversationHistory. Whenever an instance is created I wish

  • 0

I have modeled a class called ConversationHistory. Whenever an instance is created I wish to set the current date and current time.

class ConversationHistory(models.Model):
    contact_date        = models.DateField(_(u"Conversation Date"),      blank=True)
    contact_time        = models.DateTimeField(_(u"Conversation Time"),  blank=True)

    def __init__(self, *args, **kwargs):
        super(ConversationHistory, self).__init__(*args, **kwargs)
        self.contact_date    = datetime.datetime.now()
        self.contact_time    = datetime.datetime.now()

The idea is that the user can later still adjust the date and time as two different fields.

I am now a bit lost how to make the time field only to show and accept time, rather than date and time. I recon it is not possible to have a time field without datetime, but then how would I show only the time in the form?

  • 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-07T07:00:26+00:00Added an answer on June 7, 2026 at 7:00 am

    If you want only time, TimeField is what you need:

    class ConversationHistory(models.Model):
        contact_date = models.DateField(_(u"Conversation Date"), blank=True)
        contact_time = models.TimeField(_(u"Conversation Time"), blank=True)
    

    You can take advantage of the auto_now_add option:

    class TimeField([auto_now=False, auto_now_add=False, **options])

    A time, represented in Python by a datetime.time instance. Accepts the
    same auto-population options as DateField.

    If you use the auto_now_add, it will automatically set the field to now when the object is first created.

    class ConversationHistory(models.Model):
        contact_date = models.DateField(_(u"Conversation Date"), auto_now_add=True, blank=True)
        contact_time = models.TimeField(_(u"Conversation Time"), auto_now_add=True, blank=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have 2 object models: class MyModel1{ int ModelID {get;set;} string Var2
have written this little class, which generates a UUID every time an object of
So I have defined a model like this: class Model extends Zend_Db_Table_Abstract { $_primary
I have a ManyToMany relationship between two classes, for instance class Customer and class
In my current project, I have classes which are modeled like the following. At
I have modeled an AJAX search after this example a long time ago. I
I have a class Cars and class Models. Car has many properties such as
Here is my setup: I have modeled my application after the SportsStore in Pro
I have a database application in which a group is modeled like this: TABLE
I have a Main method that creates a message loop called SysTrayApp: void Main()

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.