title: Displaying datetime field as hours and minutes only (no date displayed) in ModelForm
body: <p>I'm building a calendar on Django. When a user clicks a day on the calendar, he's redirected to a CreateEventForm where he can create an event happening on the day he clicked (selected_date). To save the user the hassle of having to enter the date he selected, I used get_form_kwargs() to send the selected_date to the form and prefill the start_time and end-time fields. In this way, he only needs to enter the hours and minutes for the start_time and end_time of the event.</p>
  
  <p><strong>My problem</strong></p>
  
  <p>Currently, the entire "%Y-%m-%dT%H:%M" format is displayed like so:</p>
  
  <h2><a href="https://i.stack.imgur.com/COXbX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/COXbX.png" alt="enter image description here"></a></h2>
  
  <p>I would like to display only the %H:%M. But I want to make sure that the datetime object still contains the date; except that it wouldn't be displayed to the end user, like so:</p>
  
  <p><a href="https://i.stack.imgur.com/SeScF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SeScF.png" alt="enter image description here"></a></p>
  
  <p>I've tried to format the datetime object using form widgets, but it doesn't seem to work. When I format the field to '%H:%M', the field displays like so:</p>
  
  <p><a href="https://i.stack.imgur.com/bi5mY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bi5mY.png" alt="enter image description here"></a></p>
  
  <p><strong>Forms</strong></p>
  
  <pre><code>class EventForm(ModelForm):
    class Meta:
      model = Event
      widgets = {
        'start_time': DateInput(attrs={'type': 'datetime-local'}, format='%H:%M'),
        'end_time': DateInput(attrs={'type': 'datetime-local'}, format='%H:%M'),
      }
      fields = '__all__'
  
    def __init__(self, selected_date, *args, **kwargs):
      super(EventForm, self).__init__(*args, **kwargs)
      self.fields['start_time'].initial = selected_date
      self.fields['end_time'].initial = selected_date
      self.fields['start_time'].input_formats = ('%H:%M',)
      self.fields['end_time'].input_formats = ('%H:%M',)
  </code></pre>
  
  <p><strong>Models</strong></p>
  
  <pre><code>class Event(models.Model):
      title = models.CharField(max_length=200)
      description = models.TextField()
      start_time = models.DateTimeField()
      end_time = models.DateTimeField()
  
      def get_absolute_url(self):
          return reverse('cal:calendar')
  </code></pre>
  
  <p><strong>Views</strong></p>
  
  <pre><code>class EventCreateView(generic.CreateView):
      model = Event
      template_name = 'cal/event.html'
      form_class = EventForm
  
      def get_form_kwargs(self):
          kwargs = super(EventCreateView, self).get_form_kwargs()
          selected_date_str = self.request.GET.get('date', None)
          selected_date = datetime.strptime(selected_date_str, '%Y-%m-%d')
          kwargs.update({'selected_date': selected_date})
          return kwargs
  
  class EventUpdateView(generic.UpdateView):
      model = Event
      template_name = 'cal/event.html'
      form_class = EventForm
  </code></pre>
  
  <p><strong>Template</strong></p>
  
  <pre><code>{% extends 'cal/base.html' %}
  {% load crispy_forms_tags %}
  
  {% block title %}
  Event
  {% endblock %}
  
  {% block content %}
  &lt;div class="clearfix"&gt;
    &lt;a class="btn btn-info left" href="{% url 'cal:calendar' %}"&gt; Calendar &lt;/a&gt;
  &lt;/div&gt;
  &lt;div class="container"&gt;
  
  &lt;form method="post"&gt;
    &lt;div class="form-group"&gt;
        {% csrf_token %}
        {% if form.instance.pk %}
            &lt;h3 class="center"&gt;{{ form.instance.start_time }}&lt;/h3&gt;
        {% else %}
            &lt;h3 class="center"&gt;{{selected_date}}&lt;/h3&gt;
        {% endif %}
  
        &lt;div class="col-4"&gt;{{ form.title | as_crispy_field }}&lt;/div&gt;
        &lt;div class="col-4"&gt;{{ form.description | as_crispy_field }}&lt;/div&gt;
        &lt;div class="col-4"&gt;{{ form.start_time | as_crispy_field }}&lt;/div&gt;
        &lt;div class="col-4"&gt;{{ form.end_time | as_crispy_field }}&lt;/div&gt;
  
        {% if form.instance.pk %}
            &lt;a href="{% url 'cal:event_delete' pk=event.pk %}" class="btn btn-danger"&gt; Delete &lt;/a&gt;
        {% endif %}
        &lt;button type="submit" class="btn btn-info"&gt; Submit &lt;/button&gt;
  
  &lt;/div&gt;
  
  &lt;/form&gt;
  {% endblock %}
  </code></pre>