How can I enter the time in Django? [closed]

1

I need help I am developing an application in which the user enter a time from a form, and managed to enter the date but the client wishes to enter the time in 2:00 pm format, but never managed a model for this task can someone help me as I can do it in django thanks

Good to clarify a bit what the client wants is to enter the time from a WEB page in AM / PM format, example 2:30 PM, but I do not know how to create the models this field, at the moment create time = models.TimeField (), but when calling it from the Template it only shows me a blank box and when entering the time it does not store it in the database.

What the client wants is a kind of clock on the website to enter the time and then with this time to make a statistical query.

    # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.db import models
from django.forms import ModelForm
from datetime import datetime
from django import forms
from django.forms import extras
from django.forms.extras.widgets import SelectDateWidget
from django.utils import timezone
from django.core.validators import RegexValidator
from datetime import date
import datetime

# Create your models here.


class DatosCarpeta(models.Model):


    fecha = models.DateTimeField(['%Y-%m-%d'])
    fechaf = models.DateTimeField(['%Y-%m-%d'], blank=True, null=True)
    hora = models.TimeField(['%I:%H %p'], blank=True, null=True)

    def get_absolute_url(self):
        return reverse('nuevafecha', kwargs={'pk': self.pk})


from django import forms
from oficios.models import DatosCarpeta
import datetime
from django.forms.extras.widgets import SelectDateWidget
from django.utils import timezone
from functools import partial
from django.conf import settings
from datetimewidget.widgets import DateTimeWidget
from django.forms.extras.widgets import SelectDateWidget
class UploadForm(forms.Form):
    fecha=forms.DateField(label=("Start date"),
                                    initial=timezone.now().date(),
                                    input_formats=['%Y-%m-%d'],
                                    widget=forms.DateInput(format = '%Y-%m-%d'))
    fechaf = forms.DateField(label=("Start date"),
                                    initial=timezone.now().date(),
                                    input_formats=['%Y-%m-%d'],
                                    widget=forms.DateInput(format = '%Y-%m-%d'), required=False)

    hora=forms.TimeField(['%I:%H %p'])
    class Meta:
        model=DatosCarpeta
        fecha=forms.DateField(input_formats=settings.DATE_INPUT_FORMATS )
        fields = '__all__'


<html>
<head>
    {% load static from staticfiles %} 
    <link rel="stylesheet" href= "{% static "css/oficios/css/style.css" %}">
    <link rel="stylesheet" href= "{% static "css/oficios/css/style.css" %}" type="text/css" media="all">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Ingreso De Oficios</title>
    <link rel="stylesheet" href="{% static "jsq/jquery-ui.css" %}">
    <link rel="stylesheet" href="{% static "jsq/style.css" %}">
    <script src="{% static "jsq/jquery-1.12.4.js" %}"></script>
    <script src="{% static "jsq/jquery-ui.js"%}"></script>
    <script>
         $( function() {
            $( "input[name^=fecha]" ).datepicker({ dateFormat: 'yy-mm-dd' });
        } );
    </script>
    <script>
        function clicked(e)
        {
            if(!confirm('Desea Ingresar El Oficio'))e.preventDefault();
        }
    </script>
    <script src="//widget.time.is/es.js"></script>
    <script>
        time_is_widget.init({Colombia_z11b:{template:"TIME<br>DATE", date_format:"year-monthnum-daynum"}});
    </script>
     <style>
            body{font:14px/1.5 "Times New Roman", Georgia, Serif; padding:0 10px;}
            a:link, a:visited{text-decoration:none; color:#416CE5; border-bottom:1px solid #416CE5;}

    </style>

    <title>Infreso De Oficios</title>

</head>



<body>
    <form action="{%  url 'carpetas' %}" method="POST" enctype="multipart/form-data">{% csrf_token %}
<td><p align="center">{{form.hora}}</p></td>

         <div class="content1">
                <input type="submit" value="Ingresar Oficio"  onclick="clicked(event)" >
            </div>     


    </section>  
    </form>


    <table align="center">
        <tr>

            <th></th>
            <th>
            <div style="text-align:center;width:250px;padding:1em 0;"> <h2><a style="text-decoration:none;"></h2> <iframe src="https://www.zeitverschiebung.net/clock-widget-iframe-v2?language=es&timezone=America%2FBogota" width="100%" height="150" frameborder="0" seamless></iframe> <small style="color:black;"></div>
            </th>
            <th></th>
        </tr>        
    </table>


    <form action="{%  url 'carpetas' %}" method="POST">{% csrf_token %}
         <table align="center">
            <tr align="center">
                <td>
                    <div class="menu">
                        <div class="arrow"></div>
                            <a href="/menu" > Menu <span class="icon octicon octicon-person"></span> </a>
                        </div>
                    </div>        
                </td>
            </tr>   
        </table>    
    </form>

</body>
</html>
    
asked by mikey 11.08.2017 в 15:20
source

0 answers