Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#15274 closed (fixed)

UpdateView raises exception about overiding get_object

Reported by: sergeybe@… Owned by: nobody
Component: Generic views Version: 1.3-beta
Severity: Keywords: blocker
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've defined the view class:

class OneAuthorUpdate(generic.UpdateView):

    def get_object(self):
        return Author.objects.get(pk=1)

But next exception raises:

ImproperlyConfigured: OneAuthorUpdate is missing a queryset. Define OneAuthorUpdate.model, OneAuthorUpdate.queryset, or override OneAuthorUpdate.get_object()

Attachments (1)

tests_for_get_object.patch (3.8 KB ) - added by Sergey N. Belinsky <sergeybe@…> 14 years ago.
Tests for UpdateView and get_object method

Download all attachments as: .zip

Change History (6)

by Sergey N. Belinsky <sergeybe@…>, 14 years ago

Attachment: tests_for_get_object.patch added

Tests for UpdateView and get_object method

comment:1 by Russell Keith-Magee, 14 years ago

Keywords: blocker added
milestone: 1.3
Triage Stage: UnreviewedAccepted

Confirmed that the test case fails as described; need to dig in closer to see exactly why. Marking as a blocker for the moment, because at the very least, it's confusing.

comment:2 by Russell Keith-Magee, 14 years ago

I've found the cause -- you've overridden get_object, but you haven't provided a form, so the call to get_form_class() is calling get_queryset() as a cheats way to find the model that can be used to automatically construct a ModelForm.

The simple workaround -- specify a form_class. I'm looking into what we can do as a permanent solution.

comment:3 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

In [15540]:

Fixed #15247 -- Ensured that if a SingleObject? view defines get_object but not get_queryset, the ModelFormMixin? doesn't fail. Thanks to Sergey N. Belinsky for the report and test case.

(Fat fingers attributed this to the wrong ticket)

comment:4 by Sergey N. Belinsky <sergeybe@…>, 14 years ago

It works now. Thank you!

comment:5 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top