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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:55:02+00:00 2026-06-15T08:55:02+00:00

I have a modelform and im creating additional fields (that do not exist in

  • 0

I have a modelform and im creating additional fields (that do not exist in model) for its form.

I know you can reorder the fields in modelform like it says in the docs.

But the problem is – i want the additional fields to be rendered BEFORE the other fields.

Is it possible to somehow reorder the fields of the form before rendering? How does form object keep track of the order of its fields anyway?

Alan

  • 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-15T08:55:03+00:00Added an answer on June 15, 2026 at 8:55 am

    No matter. It seems i found answer already and this seems to do the trick, since i have added 2 additional fields:

        def __init__(self, *args, **kwargs):
            super(MyForm, self).__init__(*args, **kwargs)
    
            self.build_fields()
            l = len(self.fields.keyOrder)
            for i in range(0,2):
                f = self.fields.keyOrder[l-1]
                self.fields.keyOrder.pop(l-1)
                self.fields.keyOrder.insert(0, f)
    

    This above was my initial fix. Later on i found out that it did not cut any more. Then i did this :

    class AlertForm(forms.ModelForm):
        class Meta:
            model = Message
            fields = model_fields
    
        def __init__(self, *args, **kwargs):
            super(AlertForm, self).__init__(*args, **kwargs)
    
            self.build_fields()
            newKeyOrder = []
            newKeyOrder.append('field_that_had_to_be_first')
            if typechange:
                newKeyOrder.append('field_thats_sometimes_necessary')
            newKeyOrder += model_fields 
            self.fields.keyOrder = newKeyOrder
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model form that contains a DecimalField() with max_digits set to 5.
I have a modelform that will either create a new model or edit an
i have a django modelform that some of it's fields are required. i'm using
I have a very complicated form and I choose to not use ModelForm since
I have something like this in form : class EventForm(ModelForm): reg_due_date = forms.DateTimeField(input_formats=('%d/%m/%Y %H:%M',),
I have a model with many fields, for which I am creating two partial
I'm creating a form based on a model, where I have a boolean field
I have a ModelForm with several fields. Some of them should not be checked
I have a ModelForm field that is based on the following Model: class Phrase(models.Model):
I have a model that looks like this class RSVP (models.Model): def __unicode__(self): return

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.