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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:55:01+00:00 2026-06-05T14:55:01+00:00

I am using Django and Datepicker together with Twitter-Bootstrap and I want the form.fields

  • 0

I am using Django and Datepicker together with Twitter-Bootstrap and I want the form.fields to have same class and same id if they are of same widget(DateInput). In specific, i would like to change the id accordingly. It should have a different id every time.

This is the class i defined below. How do i change the id to be a different one every time.

class MyDatePicker(forms.DateInput)
  def __init__(self, *args, **kwargs):
      attrs = kwargs.pop("attrs",{})
      attrs["class"] = "datepick" 
      attrs["id"] ="date_1"
      kwargs["attrs"] = attrs
      super(MyDatePicker, self).__init__(*args, **kwargs)

How do i go about doing it?Need some help on it…Would welcome any suggestion…

  • 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-05T14:55:03+00:00Added an answer on June 5, 2026 at 2:55 pm

    You could register a templatetag to find out the widget type:

    @register.filter('klass')
    def klass(obj):
        return obj.__class__.__name__
    

    Then in your template:

    {% load your_filter_module %}
    <form id="form" enctype="multipart/form-data" class="form-horizontal" method="POST" action="">{% csrf_token %}
        <fieldset>
            {{ form.non_field_errors }}
            {% for field in form %}
                <div class="control-group{% if field.errors %} error{% else %}{% if form_errors %} success{% endif %}{% endif %}">
                    <label class="control-label" for="{{ field.auto_id }}">{% trans field.label %}</label>
                    <div class="controls">
                        {% if field.field.widget|klass == "CheckboxInput" %}
                            <label class="checkbox">
                                <input type="checkbox" id="{{ field.auto_id }}" name="{{ field.name }}"{% if field.value == "on" %} checked{% endif %}>
                                {% trans "Some random text" %}
                            </label>
                        {% endif %}
                        # ... etcetera continue check for other classes ...
    

    Note: A cleaner DRY approach would be to add the loop and class logic (horizontal/vertical etc) to a filter returning a html widget

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Django Crispy Forms together with Twitter-bootstrap and following this page: http://django-crispy-forms.readthedocs.org/en/d-0/tags.html#bootstrap-layout-objects
Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
Am using Django's form for my login page. I want to set focus to
I'm using Django for our project. And I have created a form using Django
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
Am using django social-auth authentication for my app.After login to facebook or twitter from
I am using django-registration and would like to have a different page for failed
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
I have a datefield named pub_date in my django project. I want to use

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.