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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:09:32+00:00 2026-05-11T18:09:32+00:00

I am making a custom form object in Django which has an overrided __init__

  • 0

I am making a custom form object in Django which has an overrided __init__ method. The purpose of overriding the method is to dynamically generate drop-down boxes based on the new parameters.

For example,

class TicketForm(forms.Form):
    Type = Type.GetTicketTypeField()

    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
                  initial=None, label_suffix=':', empty_permitted=False, 
                  ticket=None):

        if ticket:
           self.__class__.State = State.GetTicketStateField(ticket.Type)
           super(forms.BaseForm, self ).__init__(data=data, files=files, 
                  auto_id=auto_id, prefix=prefix, initial=initial, 
                  label_suffix=label_suffix, empty_permitted=empty_permitted)

This solution does not work. It appears that the fields are created before the __init__ is called. I would assume this problem would be pretty common. What would be the Django way of handling these classes of problems.

  • 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-11T18:09:32+00:00Added an answer on May 11, 2026 at 6:09 pm

    You can dynamically modify your form by using the self.fields dict. Something like this may work for you:

    class TicketForm(forms.Form):
    
      Type = Type.GetTicketTypeField()
    
      def __init__(self, ticket, *args, **kwargs):
        super(TicketForm, self).__init__(*args, **kwargs)
        self.fields['state'] = State.GetTicketStateField(ticket.Type)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a custom input method for the iPad, I want to be able
Hi im making a custom Textbox i got everty thing working but how do
I am making an application that does some custom image processing. The program will
Does anybody know the logic behind making DataSourceSelectArguments sealed? I've implemented a custom DataSource
I am making use of django-registration and django-profile to handle registration and profiles. I
I have a custom form that's returning the values to the main form but
I'm making a custom slider component. The head (the thing that you drag) is
I'm making a custom view that I want to be bindings/core data compatible and
So basically im making a custom button. Desired Behaviour: When a user mouses over,
Briefly: I'm making a custom view, I want a field listing the two taxonomy

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.