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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:36:05+00:00 2026-06-04T12:36:05+00:00

I have a very complicated form and I choose to not use ModelForm since

  • 0

I have a very complicated form and I choose to not use ModelForm since I needed flexibility and control over the fields. Since I am not using ModelForm, I can’t simply do something like instance=order, where order = Order.objects.get(pk=1).

Currently I am pre-populating every field with initial in the forms.py as oppose to the views.py like this

self.fields['work_type'] = forms.ChoiceField(choices=Order.WORK_TYPE_CHOICES, initial=order.work_type)

But I was wondering if I could pass the entire order object to a form or do I have to declare initial to every field?

Is there a way to do something like

order_form = OrderEditForm(data=request.POST, initial=order)

in views.py?

  • 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-04T12:36:06+00:00Added an answer on June 4, 2026 at 12:36 pm

    For future reference to other people:

    I have since found out after reading SO’s comments and answers that it’s better to use ModelForm even if you end up explicitly defining every field manually (using something like self.fields['foo'] = forms.CharField()).

    In any case, if you are trying to pass a dictionary of current values in a form then the best (built-in) way to convert a model to a dictionary is actually using model_to_dict:

    from django.forms.models import model_to_dict
    
    order = Order.objects.get(pk=1)
    dictionary = model_to_dict(order)
    form = OrderEditForm(dictionary)
    

    I got the solution from this blog. I hope this will be helpful for someone.

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

Sidebar

Related Questions

I have put together a very complicated search form. Using arrays I have managed
I have a very complicated form which has multiple stages in it. Each stage
We have a not very complicated but big (i.e. lots of files) Visual Studio
I have a very complicated site built on CSS3 that has html elements 3d-transformed,
I have a rather complicated (and very inefficient) way of getting utilisation from a
Im having a very strange problem, i have a complicated view that returns incorrect
I have a form that asks users to input numbers into multiple form fields.
I have a very complicated windows application which has 8 forms. There are Previous
This is a very simple form that I have found on the web (as
I have a very complicated issue, but if I can do this, then I

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.