1

I subscribed the code of my model, and after this i'm rendering this form django to put on a bootstrap form. I'm trying, without no sucess, put a datepicker in this form, but I dont found it in anywhere how to do this.

This is my model:

class Usuario(User):
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    birthday = models.DateField("Birthday")
    class Meta:
       verbose_name = "Usuario"

This other code is about the form:

class FormUsuario(UserCreationForm):

class Meta:
    model = Usuario
    fields = ("username", "email", "birthday")

def __init__(self, *args, **kwargs):
    super(FormUsuario, self).__init__(*args, **kwargs)
    self.fields['username'].widget.attrs['placeholder'] = "Usuário"
    self.fields['email'].widget.attrs['placeholder'] = "Email"
    self.fields['password1'].widget.attrs['placeholder'] = "Senha"
    self.fields['password2'].widget.attrs['placeholder'] = "Confirmar senha"
    self.fields["birthday"].help_text = "mm/dd/aaaa" 
    self.fields['email'].required = True

When I used {% csrf_token %} {{ form|bootstrap_horizontal }} on template, is not show a datepicker.

{% load bootstrap %}
<form class="form-horizontal" method="POST" action="/cadastro/">
   {% csrf_token %}
   {{ form|bootstrap_horizontal }}
   <div class="form-group">
     <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-success btn-lg btn-block">Salvar</button>
     </div>
   </div>
 </form>

{% endblock %}

How can I make up a datepicker on my bootstrap form?

  • There is no datepicker built in to either Django or django-bootstrap-form. You either need to add your own widget, or use one of the many third party libraries available e.g., [django-bootstrap3-datetimepicker](https://github.com/nkunihiko/django-bootstrap3-datetimepicker). – solarissmoke Jul 12 '16 at 03:00
  • Possible duplicate of [What's the cleanest, simplest-to-get running datepicker in Django?](http://stackoverflow.com/questions/3367091/whats-the-cleanest-simplest-to-get-running-datepicker-in-django) – solarissmoke Jul 12 '16 at 03:00

0 Answers0