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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:17:40+00:00 2026-06-18T22:17:40+00:00

I have a model like this class Timer(models.Model): Represents a timing system start_time =

  • 0

I have a model like this

class Timer(models.Model):
"""Represents a timing system"""

   start_time = models.DateTimeField(default=datetime.datetime.now())
   end_time = models.DateTimeField()

and a form that takes this as the model

class JobForm(forms.ModelForm):

    class Meta:
        exclude = ['slug','author','duration',]
        model = Job

Trouble comes in when i want to add some timing info, and by that i mean that i have to enter it in the long format

DD-MM-YYYY HH:MM:SS 

the times will be added in real time on the same day as they happen, so the long format looks like a waste of effort, i would rather do it as

HH:MM

i cant use model.TimeField because i will calculate a duration between a start time and the end time, and someone may straddle midnight by timing their sleep or who knows what else.
How would i allow input in HH:MM and have it as datetimefield (eventualy after some effort)? Id like the code to assume the same date as the current date give HH:MM

  • 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-18T22:17:42+00:00Added an answer on June 18, 2026 at 10:17 pm

    After looking at the forms documentation, this is what iv decided to do, since i didn’t understand @cclerville’s suggestion (maybe django is poor?)
    here goes:
    in my forms.py

    class MyDateTimeField(forms.Field):
    
        def to_python(self, value):
            # Return an empty list if no input was given.
            if not value:
                return []
            import datetime 
            today = datetime.date.today()
            hhmm = value.split(':')
            val= datetime.datetime.combine(datetime.date.today(), datetime.time(int(hhmm[0]),int(hhmm[1])))
            return val
    

    and the form itself:

    class JobForm(forms.ModelForm):
        end_time = MyDateTimeField()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've a problem with my tabularinline field. I have model like this class Product(models.Model):
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model.py like this: class EventTypeCategory(models.Model): name = models.CharField(max_length=50, verbose_name=Name) user =
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a model which looks like this: class MyModel(models.Model) value = models.DecimalField() date
I have a model that looks like this: class ProjectImage(models.Model): big_thumb = ThumbnailField(upload_to='profiles', size=(500,
I have a model that looks something like this class Post(models.Model): id = models.IntegerField(unique=True,
I have a model which describes an event like this: class Event(models.Model): date =
In Django, I have an app with models like this: class Artist(models.Model): name =

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.