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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:51:11+00:00 2026-06-11T01:51:11+00:00

Trying to instance a model form in django, I am passing in an instance

  • 0

Trying to instance a model form in django, I am passing in an instance and I get validation errors out, despite the data being entered from the very same form minutes prior. ignore the extra fields stuff I have tried removing it and the issue persists. It adds extra fields from a separate key value table.

Django Version 1.3

def edit(request,company_uuid,contact_uuid,address_uuid):
    mcompany = get_object_or_404(models.Company, uuid = company_uuid)
    extra_questions, extra_ids = get_questions(request, 2)
    if request.method == 'POST': # If the form has been submitted...
        form = forms.EditCompanyForm(request.POST,instance=mcompany, extra=extra_questions, extra_ids=extra_ids)
        if form.is_valid():
            fModel = form.save(commit = False)
            for (question, answer) in form.extra_answers():
                save_answer(request, question, answer, mcompany.uuid, 2)
            form.save()    
            url = reverse('contacts_details',kwargs={'company_uuid':mcompany.uuid,
                                                                   'address_uuid':address_uuid,
                                                                   'contact_uuid':contact_uuid})
            return HttpResponseRedirect(url)
    else:
        form = forms.EditCompanyForm(request.POST,instance=mcompany, extra=extra_questions, extra_ids=extra_ids)
    return share.output_page(request,'contacts/edit.html',{'form': form,
                                                            'company_uuid':mcompany.uuid,
                                                            'address_uuid':address_uuid,
                                                            'contact_uuid':contact_uuid})  

class EditCompanyForm(jsforms.JMSModelForm):
    """
    The Company form with the contacts fields included
    """
    name = forms.CharField(label = _('Company Name'),widget = forms.TextInput(attrs={'class':'large-input-box'}))
    discount=forms.FloatField(widget = jsforms.StandardUnit("PC"),required=False)
    allow_download = forms.BooleanField(required=False,label=_('Allow download'))

    def __init__(self, *args, **kwargs):

        extra = kwargs.pop('extra')
        extra_id = kwargs.pop('extra_ids')
        super(EditCompanyForm, self).__init__(*args, **kwargs)

        for i, question in enumerate(extra):
            settings = ExtraFieldSetup.objects.get(uuid=extra_id[i])
            if settings.type == 2:
                list = []
                list_partial = str(settings.extra).split(':')
                for choice in list_partial:
                    x = choice, choice
                    list.append(x)
                self.fields['custom_%s' % i] = forms.ChoiceField(choices=list, label=question, required=False)
            else:
                self.fields['custom_%s' % i] = forms.CharField(label=question, required=False)

    def extra_answers(self):
        for name, value in self.cleaned_data.items():
            if name.startswith('custom_'):
                yield (self.fields[name].label, value)

    class Meta:
        model = models.Company
        exclude = ('company', 'otherdetails', 'jms_code', 'logo', 'hidden', 'user')
  • 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-11T01:51:13+00:00Added an answer on June 11, 2026 at 1:51 am

    You’re passing in request.POST even in the GET stage of the view (after the else), when the POST dictionary will be empty, so naturally there will be validation errors.

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

Sidebar

Related Questions

I'm trying to save my model form. Django reurns InternalError: current transaction is aborted,
I'm trying to prepopulate the data in my django form based on some information,
I am trying to figure out how to pass the model object from controller
I'm trying to create an instance of my CompanyLogo model if the hash params[:vacancy]['companies']['company_logo']
I am trying to model a tree relationship in a table. For instance, there
I am trying to find out if an instance of an application (not vb.net)
I am trying to create a model instance that includes a list of model
I am trying to change a form's instance before I save it. I need
Struggling to figure out how to Over-Ride the __init__() method in my Django Form
Hey, Im trying to get the signal pre_save to work on my model but

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.