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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:29:10+00:00 2026-06-13T20:29:10+00:00

Say I have the following model defined: class Location(models.Model): name = models.CharField(max_length=20) longitude =

  • 0

Say I have the following model defined:

class Location(models.Model):
    name = models.CharField(max_length=20)
    longitude = models.CharField(max_length=30)
    latitude = models.CharField(max_length=30)

And there’s an existing Location instance with id=1

I want to post an update against this instance but I am not sure how I should send the pk/id to the server. I have two ideas in mind.

  1. Include it as part of the url (ex. ^update_location/(?P<pk>[0-9]+)/$').
  2. Include it in the POST data along with values for updating other attributes.

My question is why would I want to choose one over the other?

I am leaning more towards option 1 because it’s supported, by default, by the generic view django.views.generic.edit.UpdateView that I am using. But then I still don’t know how to choose.

  • 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-13T20:29:11+00:00Added an answer on June 13, 2026 at 8:29 pm

    I would say you can do like this:

    url(r'^update_location/(?P<location_id>\d+)/$', 'location.views.update'),
    

    and then in your view:

    def detail(request, location_id):
        // do whatever needed with location_id object
        location = Location.objects.get(id=location_id)
        return HttpResponse("You're updating location %s." % location_id)
    

    and about the form handling you can have a look at :
    https://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs

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

Sidebar

Related Questions

Let's say I have the following model: class Contest: title = models.CharField( max_length =
Let's say I have the following classes: class Votable(models.Model): name = ... class Vote(models.Model):
Ok say I have the following model: class Country < ActiveRecord::Base validates_presence_of :name validates_presence_of
Lets say we have following models. class User(db.Model): username=db.StringProperty() avatar=db.ReferenceProperty() class User(db.Model): username=db.StringProperty() avatar=db.StringProperty()
Lets say we have the following models: (simplified) class Collection(models.Model): slug = models.SlugField() class
Let's say I have the following Django model: class Info(models.Model): instrument = models.ForeignKey('Instrument') date
Say I have the following model: class Foo(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField()
Lets say a have the following Model public class FirstModel { public List<SecondModel> SecondModels
I have the following defined: class AnswerChoiceInline(admin.TabularInline): model = AnswerChoice # extra = 0
Let's say I have the following model: Person <AR def name [self.first_name,self.middle_name,self.last_name].select{|n| n.present?}.join(' ')

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.