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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:36:39+00:00 2026-05-11T11:36:39+00:00

This is a follow-up on How do you change the default widget for all

  • 0

This is a follow-up on How do you change the default widget for all Django date fields in a ModelForm?.

Suppose you have a very large number of models (e.g. A-ZZZ) that is growing with the input of other developers that are beyond your control, and you want to change the way all date fields are entered (i.e. by using jQueryUI). What’s the best way to ensure that all date fields are filled out using that new widget?

One suggestion from the cited question was:

def make_custom_datefield(f):    if isinstance(f, models.DateField):        # return form field with your custom widget here...    else:        return f.formfield()  class SomeForm(forms.ModelForm):     formfield_callback = make_custom_datefield     class Meta:        # normal modelform stuff here... 

However, is this possible to do where you don’t have explicit ModelForm’s, but url patterns come from models directly? i.e. your url config is likeso:

url(r'^A/?$', 'list_detail.object_list', SomeModelA) 

where SomeModelA is a model (not a form) that’s turned into a ModelForm by Django in the background.

At present in my system there are no Forms for each Model. The only point of creating forms explicitly would be to add the formfield_callback suggested in the prior solution, but that goes against DRY principles, and would be error prone and labour intensive.

I’ve considered (as suggested in the last thread) creating my own field that has a special widget and using that instead of the builtin. It’s not so labour intensive, but it could be subject to errors (nothing a good grep couldn’t fix, though).

Suggestions and thoughts are appreciated.

  • 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. 2026-05-11T11:36:40+00:00Added an answer on May 11, 2026 at 11:36 am

    It sounds like you want to do this project-wide (ie: you’re not trying to do this in some cases, but in ALL cases in your running application).

    One possibility is to replace the widget attribute of the DateField class itself. You would need to do this in some central location… something that is guaranteed to be loaded by every running instance of the django app. Middleware can help with this. Otherwise, just put it in the __init__ file of your app.

    What you want to do is re-assign the widget property for the forms.DateField class itself. When a new DateField is created, Django checks to see if the code specifies any particular widget in the field property definition. If not, it uses the default for DateField. I’m assuming that if a user in your scenario really defined a particular widget, you’d want to honour that despite the change to your global API.

    Try this as an example of forcing the default to some other widget… in this case a HiddenInput:

    from django import forms forms.DateField.widget = forms.HiddenInput  class Foo(forms.Form):     a = forms.DateField()  f = Foo() print f.fields['a'].widget # results in <django.forms.widgets.HiddenInput object at 0x16bd910> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer As I understand it, the open session in view pattern… May 11, 2026 at 3:13 pm
  • added an answer The easiest way is to have a factory where all… May 11, 2026 at 3:13 pm
  • added an answer The first parameter of the RouteLink method is for the… May 11, 2026 at 3:13 pm

Related Questions

I've had a hard time trying to find good examples of how to manage
I'm just looking through some of the webmaster stats that Google provides , and
We have some software which relied on certain behavior from another ( very commonly
So I'm newly in charge of projects at my company (We're still only 2

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.