I still haven't seen a definitive reason *why* the mixin doesn't do the check for the object, other than: 'Personally, I don't like this change'
Shouldn't the mixin stand on its own and not require going to the django docs to find the dependency that the user needs to set self.object in get/post/etc? This same class even does checks for other attributes - e.g. raising an exception if the model class isn't set. It also sets `queryset = None`, so why wouldn't it do the same for `object`? On Friday, August 14, 2015 at 2:38:59 PM UTC-7, Tim Graham wrote: > > Yes, the proposal isn't new. Here is some related discussion: > * https://code.djangoproject.com/ticket/21801 > * https://github.com/django/django/pull/2260 > * https://github.com/django/django/pull/4595 > * https://github.com/django/django/pull/4526 > > On Friday, August 14, 2015 at 3:38:58 PM UTC-4, steve byerly wrote: >> >> In the `SingleObjectMixin` generic view mixin, the `get_context_data` >> method checks if the object is set by using: `if self.object` >> >> I often include this mixin just for the `get_object` functionality and >> error handing it brings. I end up having to set `object = foo` or `object = >> None` to suppress the AttributeError >> >> It seems like the class should initialize `self.object = None` instead of >> relying on a derived class setting it, especially because it doesn't >> guarantee that it will be added to the context - it only adds 'object' (and >> whatever the `context_object_name` param is) to the context if there's an >> object to add. >> >> I'm sure there has been discussion on this before, but I was unable to >> find it here/trac. >> > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/74d3ba9d-9236-4918-a7b3-64c10421691e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
