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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:56:07+00:00 2026-06-04T18:56:07+00:00

Argh. Hey all, i have a muy simple django question: And argh, i’m sorry,

  • 0

Argh. Hey all, i have a muy simple django question:

And argh, i’m sorry, i’ve read and read, and I am sure this is covered somewhere super-obviously, but i haven’t found it!

How do i edit/update a model using django? Like, the data values? Not the model fields?

Here is my code! (I’m using a home-brew version of stuff!)

Here is the urls:

url(r'^editStory/(?P<id>\d+)$',
    StoryModelView.as_view(
        context_object_name='form',
        template_name ='stories/editStory.html',
        success_template= 'stories/editStorySuccess.html'
    ),
    {},
    'editStory'
),

Here is the view:

def get(self,request,id=None):
    form = self.getForm(request,id)
    return self.renderValidations(form)

def getForm(self, request,id):
    if id:
        return self.getModelById(request,id)
    return StoryForm()

def getModelById(self,request,id):
    theStory = get_object_or_404(Story, pk=id)
    if theStory.user != request.user:
        raise HttpResponseForbidden()
    return StoryForm(theStory)

def renderValidations(self,form):
    if self.context_object_name:
        contextName = self.context_object_name
    else:
        contextName = 'form'
    if self.template_name:
        return render_to_response(self.template_name,{contextName:form})
    else :
        return render_to_response('stories/addStory.html',{contextName:form})

def getPostForm(self,request,id):
    if id:
        theStory = self.idHelper(request,id)
        return StoryForm(request.POST,theStory)
    return StoryForm(request.POST)

def processForm(self,form,request):
    theStory = form.save(commit=False)
    theStory.user = request.user
    return theStory

Here is the template code:

{% block content %}
    <h3>Edit story</h3>
    <form action="" method="post">
        {%  csrf_token %}
        {%  for field in form %}
            <div class="fieldWrapper">
                {{ field.errors }}
                {{ field.label_tag }} {{ field }}
            </div>
        {% endfor %}
        <input type="submit" value="Submit"/>
    </form>
{% endblock %}

try as i might, i either:

  1. get an error
  2. get nothing

i get an error with the code as-displayed, caused by this line

    {% for field in form %}

and with the error of:

Caught AttributeError while rendering: 'Story' object has no attribute 'get'

or i get nothing – no data at all – if i change my “getModelById” method to read:

def getModelById(self,request,id):
    theStory = get_object_or_404(StoryForm, pk=id)
    if theStory.user != request.user:
        raise HttpResponseForbidden()
    return theStory

StoryForm is one of those “ModelForm” things, and its model is “Story”.

SO! The question:

how do i fix this code to make it work? What have i done wrong?

  • 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-04T18:56:08+00:00Added an answer on June 4, 2026 at 6:56 pm

    You don’t show what your class is inheriting from, but it seems like you’re just using a standard single object display view. Instead, you should use one of the editing mixins that are provided for this purpose.

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

Sidebar

Related Questions

argh, this should be an easy one. How can I set the directory that
This problem is probably embarrassingly simple. I'm trying to give python a spin. I
ARGH! What's wrong with this?? $(document).ready(function() { var monkeyTrouble = $('#monkeyTrouble').attr('rel'); if (monkeyTrouble =
I have never been so annoyed with this wpf toolkit. The documentation is just
Hey all. I'm having some trouble getting punctuation to be stripped out of an
I have a UIViewController and I wish to place a simple UITabBar like the
Argh! Everything has been totally fine, then all of a sudden I started getting
I added this code to my web page: <input id='argh' type='text' onfocus='this.value=7'> Unless the
Argh! I know I will get this eventually but at this point I'm almost
This is probably an easy one, but I can't figure it out. argh... C#

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.