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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:50:58+00:00 2026-05-13T06:50:58+00:00

I have a simple view function that’s designed to allow the user to choose

  • 0

I have a simple view function that’s designed to allow the user to choose from items listed in an html table (records). Clicking on a record should divert the user to the template from which he can edit that specific record. The code is as follows:

def edit_record(request):
        if request.method == 'POST':
                a=ProjectRecord.objects.get()
                form = RecordForm(request.POST, instance=a)
                if form.is_valid():
                        form.save()
                        return HttpResponseRedirect('/')
        else:
                a=ProjectRecord.objects.get()
                form = RecordForm(instance=a)
        return render_to_response('productionModulewire.html', {'form': form})

The problem is that the function works perfectly well ONLY so long as there is only 1 record in the database. As soon as I add another, I get a multiple returned item error.
I suspect it has something to do with “objects.get()” but I don’t know how to correctly structure the view?

The url is simple (perhaps too much so):

(r'^edit/', edit_record),

and the model looks like this:

class ProjectRecord(models.Model): 
    client = models.CharField(max_length=50, choices=CLIENT_CHOICES)
    account = models.CharField(max_length=50, choices=ACCOUNT_CHOICES)
    project_type = models.CharField(max_length=50, choices=TYPE_CHOICES)
    market = models.CharField(max_length=50, choices=MARKET_CHOICES)
    agencyID = models.CharField(max_length=30, unique=True, blank=True, null=True)
    clientID = models.CharField(max_length=30, unique=True, blank=True, null=True)
    prjmanager = models.CharField(max_length=64, unique=False, blank=True, null=True)
    acclead = models.CharField(max_length=64, unique=False, blank=True, null=True)
    artdirector = models.CharField(max_length=64, unique=False, blank=True, null=True)
    prdlead = models.CharField(max_length=64, unique=False, blank=True, null=True)
    intlead = models.CharField(max_length=64, unique=False, blank=True, null=True)
    prjname = models.CharField(max_length=200, unique=True)
    prjstatus = models.CharField(max_length=50, choices=STATUS_CHOICES)
    as_of = models.DateField(auto_now_add=False)
    format = models.CharField(max_length=64, unique=False, blank=True, null=True)
    target_studio = models.DateField(unique=False, blank=True, null=True)
    mech_return = models.DateField(unique=False, blank=True, null=True)
    comp_return = models.DateField(unique=False, blank=True, null=True)
    target_release = models.DateField(unique=False, blank=True, null=True)
    record_added = models.DateField(auto_now_add=True)
    record_modified = models.DateTimeField()
    studio_name = models.CharField(max_length=64, unique=False, blank=True, null=True)
    studio_process = models.CharField(max_length=64, unique=False, blank=True, null=True, choices=PROCESS_CHOICES)
    to_studio = models.DateTimeField(unique=False, blank=True, null=True)
    from_studio = models.DateTimeField(unique=False, blank=True, null=True)
    studio_name2 = models.CharField(max_length=64, unique=False, blank=True, null=True)
    studio_process2 = models.CharField(max_length=64, unique=False, blank=True, null=True, choices=PROCESS_CHOICES)
    to_studio2 = models.DateTimeField(unique=False, blank=True, null=True)
    from_studio2 = models.DateTimeField(unique=False, blank=True, null=True)
    comments = models.TextField(max_length=500, unique=False, blank=True, null=True)
    summary = models.TextField(max_length=500, unique=False, blank=True, null=True)
    upload_pdf = models.CharField(max_length=50, unique=False, blank=True, null=True)
    upload_achive = models.CharField(max_length=50, unique=False, blank=True, null=True)

    def __unicode__(self):
        return u'%s' % self.prjname

    class Admin: 
        pass

from which the model form “RecordForm” was derived.

  • 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-13T06:50:58+00:00Added an answer on May 13, 2026 at 6:50 am

    The important thing about get is “get what?”

    When you say

    a=ProjectRecord.objects.get()
    

    you neglected to provide any selection criteria. Which row do you want from the database?

    Which row? Hmmmm… How does the GET transaction know which row is going to be edited?

    Usually, we put that in the URL.

    So, you’ll need to update your urls.py to include the record ID on the URL path. You’ll need to update your view function definition to accept this record ID. Finally, you’ll need to update GET and POST to use this record identification which came from the URL.


    Update urls.py to include the object id. See http://docs.djangoproject.com/en/1.1/topics/http/urls/#named-groups

    urlpatterns = patterns('',
        (r'^class/(?P<object_id>\d+?)/$', 'app.views.edit_record'),
    

    Update your view function

    def edit_record( request, object_id = None ):
        if request.method == "POST":
            if object_id is None:
                return Http_404
            ProjectRecord.objects.get( pk = int(object_id) )
    
        etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.