0

I'm trying to edit the form via my edit button.

When i click update button in my form I'm getting the following error:

FieldError at /studentapp/editrow/72/
Cannot resolve keyword 'rowid' into field Choices are: address, course, id, name, pub_date, roll

My traceback shows the error originating in this line

item = get_object_or_404(Studentapp, rowid=id) this line. 

My models.py looks like this:

class Studentapp(models.Model):
    name = models.CharField(max_length=100)
    roll = models.IntegerField()
    course = models.CharField(max_length=100)
    address = models.CharField(max_length=100)
    pub_date = models.DateTimeField('date published', auto_now=True)

    def __str__(self):
        return '%s %s %s %s' % (self.name, self.roll, self.course, self.address)

    def published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

EDIT

My view:

def editrow(request, id):
    item = get_object_or_404(Studentapp, id=id)
    if request.method=="POST":
        form = EntryForm(request.POST, instance=item)
        if form.is_valid():
            post=form.save(commit=False)
            post.save()
            return HttpResponseRedirect(reverse('studentapp:index'), id)
        else:
            form=EntryForm(instance=item)
        return render(request, 'index.html',{'form':form})
    else:
        form=EntryForm(instance=item)
        return render(request, 'index.html',{'form':form})

My urls.py

url(r'^editrow/(?P<rowid>[0-9]+)/$', views.editrow, name='editrow'),

Form that i'm using to update the entry:

{% load staticfiles %}
  <form action="{% url 'studentapp:editrow' student_detail.id  %}" id="editform" method="POST">
    {% csrf_token%}

      <div class = "form-group">
    <label for = "your_name">
      Your name:
    </label>
    <input class = "form-control" id="new_name" type = "text" name="name" value="{{ student_detail.name }}" placeholder="Enter your name">
  </div>
  <div class="form-group">
    <label for = "course_name">
      Course:
    </label>
    <input id="new_course" class = 'form-control' type = "text" name="course" value="{{ student_detail.course }}" placeholder="Enter your course">
  </div>
  <div class = "form-group">
    <label for = "rollno">
      Roll No.:
    </label>
    <input id="new_rollno" type = "text" class = 'form-control' name="roll" value="{{ student_detail.roll }}" placeholder="Enter your roll number">
  </div>
  <div class = "form-group">
    <label for ="addr">
      Address:
    </label>
    <input id="new_address" type = "text" name="address" class = 'form-control' value="{{ student_detail.address }}" placeholder="Enter your address"/>
  </div>
  <input type = "submit" value="Update" id="update" class = "btn btn-success" style="font-size:18px;" />
</form>
6
  • Can you paste the entire traceback Commented Apr 25, 2018 at 19:02
  • Cannot resolve keyword 'rowid' into field. Choices are: address, course, id, name, pub_date, roll Commented Apr 25, 2018 at 19:05
  • 2
    your model doesn't have this field rowid=id. you meant id=id Commented Apr 25, 2018 at 19:10
  • what should i do then? Commented Apr 25, 2018 at 19:14
  • remove rowid, and add id, because your model does not have this field Commented Apr 25, 2018 at 19:17

1 Answer 1

1

This line is not right, your model does not have the field rowid

item = get_object_or_404(Studentapp, rowid=id) this line. # WRONG
item = get_object_or_404(Studentapp, id=id) this line. # OK

and your urls should be

url(r'^editrow/(?P<id>[0-9]+)/$', views.editrow, name='editrow'),

# url(r'^editrow/(?P<rowid>[0-9]+)/$', views.editrow, name='editrow'), # WRONG
Sign up to request clarification or add additional context in comments.

6 Comments

i tried this method. i've removed rowid still it is showing "TypeError at /studentapp/editrow/72/ editrow() got an unexpected keyword argument 'rowid'" What to do now?
I've updated my question with my view. can you tell me the error?
your urls.py , please add everything that can be concerned. your urls pattern is important to detect what's worng
i've added my urls and form also
Check my answer, bugs were in your urls as well
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.