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

  • SEARCH
  • Home
  • 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 6645729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:19:31+00:00 2026-05-26T00:19:31+00:00

I have a baseform with over 20 fields. Then I have about 15 other

  • 0

I have a baseform with over 20 fields. Then I have about 15 other forms inheriting from that form, passing in a parameter called fields which the baseform uses to delete all other fields. Best explain via example:

class BaseForm(forms.Form):
    reportid = forms.HiddenInput()
    fromdate = forms.DateField(label=_("From"), widget=widgets.AdminDateWidget())
    todate = forms.DateField(label=_("To"), widget=widgets.AdminDateWidget())
    sort_by = forms.ChoiceField(label=_("Sort by"), choices=[])
    .......

    def __init__(self, *args, **kwargs):
        fields = kwargs.pop('fields')
        #Pseudo:
        ***del self.fields[field] for field not in fields***

class SubForm(forms.Form):
    def __init__(self, *args, **kwargs):
        fields = ['reportid', 'todate']
        super(SubForm, self).__init__(fields=fields, *args, **kwargs)

The resulting form would then look like this:

class SubForm(forms.Form):
    reportid = forms.HiddenInput()
    todate = forms.DateField(label=_("To"), widget=widgets.AdminDateWidget())

My problem is that when the BaseForm is initialized for the first time, the labels are bound to the fields with the active language, and when another user logs in with another language setting (or the current user changes languages) the field labels don’t update.

I’ve come to a solution using a dict like this:

labels = {
    'todate': lambda: _("To"),
    'fromdate': lambda: _("From"),
    .....
}

and then when initializing the baseform looping through all fields and setting

self.fields[field].widget.label = labels[field]()

Do I have any nicer (read: more pythonic) way of achieving this?

  • 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-05-26T00:19:32+00:00Added an answer on May 26, 2026 at 12:19 am

    Django provides _lazy variants of the translation functions (for example ugettext_lazy) so you can ark strings for translations at the access time (as opposed to when the translation function is called).

    It’s documented in details at https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#lazy-translation

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

Sidebar

Related Questions

I have a namespace Company.UI.Forms where we have a form base class BaseForm that
I have a base class that is a Django form. The child class then
I'm using C#.Net and have a base form that is inherited by several forms.
I have a base form that I use when calling 2 forms. Previously when
From here I have created a BaseForm , then set all its BaseForm.Designer.cs private
Say I have a base form of a word and a tag from the
I have a recursive method on the base form that takes in a control
I have a winforms baseform that contain calls to certain methods that need to
Is it possible to have a variable number of fields using django forms? The
I have a base User form that I am subclassing for each use case,

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.