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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:12:19+00:00 2026-06-04T02:12:19+00:00

I understand that you can use the initiate parameter for a Form class from

  • 0

I understand that you can use the initiate parameter for a Form class from this question.

I am creating an edit form and I’m trying to figure out how to initiate values from a pre-existing object.

Do I do it in the template level or in the view level (I don’t even know how to do it in the template level)? Or maybe I need to pass the actual object to the form and initiate in the form level?

What is the best practice?


EDIT:

For @Bento: In my original Form, I’m doing something like this

class OrderDetailForm(forms.Form):
    work_type = forms.ChoiceField(choices=Order.WORK_TYPE_CHOICES)
    note = forms.CharField(widget=forms.Textarea)

    def __init__(self, creator_list=None, place_list=None, *args, **kwargs):
        super(OrderCreateForm, self).__init__(*args, **kwargs)

        if creator_list:
            self.fields['creator'] = UserModelChoiceField(
                queryset=creator_list,
                empty_label="Select a user",
            )

    def clean(self):
        super(OrderCreateForm, self).clean()

        if 'note' in self.cleaned_data:
            if len(self.cleaned_data['note']) < 50:
                self._errors['note'] = self.error_class([u"Please enter a longer note."])

                del self.cleaned_data['note']

        return self.cleaned_data

How would I do that with ModelForm?

  • 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-04T02:12:21+00:00Added an answer on June 4, 2026 at 2:12 am

    Assuming you are using a ModelForm, it’s actually fairly simple. The task is something like this: retrieve the object of the model that you want to populate your ‘edit’ for with, create a new form based on your ModelForm, and populate it with the object using ‘instance’.

    Here’s the skeleton of your view:

    def view(request): 
      obj = Model.objects.get(pk = objectpk)
      form = MyModelForm(instance = obj)
    
      return render (request, "template", {'form' = form})
    

    You can access the ‘initial’ values by using something like:

    form.fields['fieldname'].initial = somevalue
    

    And then you’d return the form like above.

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

Sidebar

Related Questions

I understand that one can use pip to install packages from svn etc. ala:
I understand that I can use the cache=TRUE option to cache an R code
I understand that this can be done at release using the maven-gpg-plugin. However, I
I'm basically trying to create a generic object in javascript that I can use
I understand that you can use ffmpeg to serve a sequence of images as
I understand that we can use the filter ant task to pick up tokens
I understand that I can use 'git push -u [repo] [br]' to make [repo]
I understand that you can use iomanip to set a precision flags for floats
I am creating a networking library in C# that I can use in any
Ey! Ok, i've come to understand that you can use AJAX calls to remote

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.