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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:49:11+00:00 2026-06-06T04:49:11+00:00

I’m trying to make a view where the user can edit DB records through

  • 0

I’m trying to make a view where the user can edit DB records through a form in a template. I’ve searched a lot of web pages (and Django docs as well) where they teach how to make these views, but they always use the “id” that Django generates for each Model. In this particular Model, I have to use an AutoField to override the “id”. Is there a way to use this AutoField as an “id” of the record with Django?

Here’s my complete model:

class T031003 (models.Model): 
   C003IDCD = AutoField(primary_key=True)
   C003INST = models.IntegerField(unique=True) #usar AutoSlug
   C003TPCD = models.CharField(max_length=1)
   C003CHCD = models.CharField(max_length=14)
   C003MTR = models.CharField(max_length=30, blank=True, null=True)
   C003CTCD = models.CharField(max_length=3)
   C003RZSC = models.CharField(max_length=60, blank=True, null=True)
   C003EML = models.EmailField(max_length = 254, blank=True, null=True)
   C003LOGA = models.CharField(max_length=20)
   C003LOGB = models.DateTimeField()
   C003LOGD = models.CharField(max_length=15, blank=True, null=True)
   C003LOGF = models.CharField(max_length=20, blank=True, null=True)

   def __unicode__(self):
       return '%s' %  self.C003MTR

   class T031003Form(ModelForm):
       class Meta:
          model = T031003
          ordering = ["-C003MTR"]
          exclude = ('C003LOGA','C003LOGB','C003LOGD','C003LOGE','C003LOGF')

And here’s the view I tried to do, but it gives me the error “No T031003 matches the given query.” and it’s right, since there is no “id” in the table:

def t031003form_edit(request, id=None):
pin = get_object_or_404(T031003, pk=id)
form = T031003Form(request.POST or None, instance=pin)
if request.method == 'POST':
    if form.is_valid():
        form = form.save(False)
        form.C003LOGA = request.user
        form.C003LOGB = datetime.date.today()
        form.C003LOGD = request.META['REMOTE_ADDR']
        form.C003LOGF = request.META['USERDOMAIN']
        form.save()
        form = T031003Form()
    else:
        return HttpResponseRedirect('/erro/')
return render_to_response('T031003Form_edit.html', {'form': form,}, context_instance=RequestContext(request))

Any help would be very appreciated!

  • 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-06T04:49:12+00:00Added an answer on June 6, 2026 at 4:49 am

    Well, thanks to the help from a close friend, I could do the trick using formsets. Here’s the view:

    def t031002form_edit(request, id_auto):
    j = get_object_or_404(T031002, pk=id_auto)
    
    T031003FormSet = modelformset_factory(T031002, can_delete=True, max_num=1)
    
    if request.method == 'POST':
        form = T031002FormSet(request.POST or None, request.FILES or None, queryset=T031002.objects.filter(pk=id_auto)) 
        if form.is_valid():
            instance = form.save(commit=False)
            form.C003LOGA = request.user
            form.C003LOGB = datetime.date.today()
            form.C003LOGD = request.META['REMOTE_ADDR']
            form.C003LOGF = request.META['USERDOMAIN']
            for reform in instance:
                reform.save()
        else:
           return HttpResponseRedirect('/erro/')
    else:
        form = T031002FormSet(queryset=T031002.objects.filter(pk=id_auto))  
    return render_to_response(('T031002Form_edit.html'), {'form': form,}, context_instance=RequestContext(request))
    

    So, with formsets, you can work nicely and with no worries. Hope it helps others with this same questioning.

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including 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.