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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:39:20+00:00 2026-05-19T06:39:20+00:00

Possibly a newbie question, so please bear with me. I have a Django form

  • 0

Possibly a newbie question, so please bear with me.

I have a Django form that edits a certain instance of a Model. In order to know which object is being edited, I have a hidden field containing the id of the object, along with the URL containing the id.

First question: Is having the id of the object in a hidden field the right way of doing it?

My (possibly unfounded) concern with having it only as part of the url is that someone could then open the page of one object id, submit the form to another, and that object will then be overwritten. That’s why I’m trying to use a hidden field.

The problem with storing the id in a hidden field is that, on validation of the form, Django complains that the object does not have an unique id (obviously).

Second question: If a unique field is part of a form, how does one tell Django to ignore the fact that that key already exists, in order to update the object?

  • 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-19T06:39:21+00:00Added an answer on May 19, 2026 at 6:39 am

    Why don’t you just use ModelForm?

    # forms.py
    # ...
    class MyForm(forms.ModelForm):
        class Meta:
            model = MyModel
    
    # views.py
    # ...    
    def my_view(request, id): 
        instance = get_object_or_404(MyModel, id=id)
        form = MyForm(request.POST or None, instance=instance)
        if form.is_valid():
            form.save()
            return redirect('next_view')
        return render(request, 'my_template.html', {'form': form}) 
    

    See https://docs.djangoproject.com/en/3.0/topics/forms/modelforms/#the-save-method for more details.

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

Sidebar

Related Questions

This is a pretty newbie question- please know I'm aware of that. I have
A newbie question from me, please. I have a large data set that I
Everyone, I am a newbie to android development. Now I have a question that
newbie question I have a multiselect box that i populate with some ajax and
Newbie Python question. I have a class that inherits from several classes, and some
I am a newbie to Hadoop. I have been reading that HDFS is mostly
another iPhone newbie question... I have the following: NSPersistentStoreCoordinator NSManagedObjectContext NSManagedObjectModel Is it possible
I am new to WebParts and have a newbie question... is it possible to
SSRS newbie question here... I have a table where one column is varbinary(max) data.
I have a newbie question in JSF, and particular in Richfaces. I need my

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.