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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:03:58+00:00 2026-05-22T02:03:58+00:00

I am inserting a new record in my model form where my model is

  • 0

I am inserting a new record in my model form where my model is child form containing a foriegn key. When I am submitting the form it give error it should be instance of the foriegn key.

Here is my model

class MMEditidState(models.Model):
  state_id = models.IntegerField(primary_key = True)
  state_dremelid = models.ForeignKey(MMDremelDump, db_column = 'state_dremelid')
  assignee = models.CharField(max_length = 50)
  state = models.CharField(max_length = 50)
  role = models.CharField(max_length = 50)
  date = models.DateTimeField() 
  class Meta:
    db_table = u'mm_editid_state'
  def __unicode__(self):
    return u'%s %s' % (self.state_dremelid, self.assignee)

  class MMEditidErrors(models.Model):
     error_id = models.IntegerField(primary_key = True)
     error_stateid = models.ForeignKey(MMEditidState, db_column = 'error_stateid')
     feature_type = models.CharField(max_length = 20)
     error_type = models.CharField(max_length = 20)
     error_nature = models.CharField(max_length = 50, null = True)
     error_details = models.CharField(max_length = 50)
     error_subtype = models.CharField(max_length = 200)
     date = models.DateTimeField()
  class Meta:
     db_table = u'mm_editid_errors'
  def __str__(self):
     return "%s" % (self.error_dremelid)
  def __unicode__(self):
     return u'%s' % (self.error_dremelid)

Here is my View

def qcthisedit(request, get_id):
  if request.method == "POST":
     form = forms.MMEditidErrorForm(get_id, request.POST)
     if form.is_valid():
        form.save()
     return http.HttpResponseRedirect('/mmqc/dremel_list/')
  else:
    form = forms.MMEditidErrorForm(get_id)
    return shortcuts.render_to_response('qcthisedit.html',locals(),
                                  context_instance = context.RequestContext(request))

Here is my form

class MMEditidErrorForm(forms.ModelForm):
   def __init__(self,get_id, *args, **kwargs):
     super(MMEditidErrorForm, self).__init__(*args, **kwargs)
     dremel = MMEditidState.objects.filter(pk=get_id).values('state_id')
     dremelid = int(dremel[0]['state_id'])
     self.fields['error_stateid'] = forms.IntegerField(initial = dremelid, 
                                                   widget = forms.TextInput(
                                                              attrs{'readonly':'readonly'}))
     feature_type  = forms.TypedChoiceField(choices = formfields.FeatureType)
     error_type  = forms.TypedChoiceField(choices = formfields.ErrorType)
     error_nature = forms.TypedChoiceField(choices = formfields.ErrorNature)
     error_details = forms.TypedChoiceField(choices = formfields.ErrorDetails)
     error_subtype = forms.TypedChoiceField(choices = formfields.ErrorSubType)
     class Meta:
        model = models.MMEditidErrors
        exclude = ('error_id','date')  

When I submit the form I am getting the error

Cannot assign "1": "MMEditidErrors.error_stateid" must be a "MMEditidState" instance.

So I have added line

get_id = MMEditidState.objects.get(pk = get_id)

Now I am getting the below mentioned error

int() argument must be a string or a number, not 'MMEditidState'

in form = forms.MMEditidErrorForm(get_id, request.POST)

Can someone help on this

Thanks
Vikram

  • 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-22T02:03:59+00:00Added an answer on May 22, 2026 at 2:03 am

    I have solved this problem by simply using the custom forms instead of model forms. While storing the data in the database, I managed myself in the views.py

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

Sidebar

Related Questions

In my gridview I have fields for inserting a new record in the footer.
Afetr inserting a new record into my CoreData store using an NSFetchedResultsController, when I
I have a trigger that is fire on inserting a new record in table
The following code generates the primaey key for the new record to be inserted
I'm having a trouble with getting the id after inserting a new Record using
I am trying to set an identity field's value before inserting the new record
I am using EF4 and MVC 2. I am inserting a new record to
So the main program is in C#. Inserting new records into a VFP database
After inserting new html to DOM,I need to add some listeners to it. But
Does std::map move around already inserted values when inserting new data ?

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.