Skip to content

Ticket/16418 #52

Closed
wants to merge 3 commits into from

2 participants

@dstufft
Django member
dstufft commented May 9, 2012

Solves #16418 by explicitly checking for subclasses not assuming anything with a _meta or model attribute is a Model or QuerySet subclass.

@akaariai akaariai commented on the diff May 27, 2012
django/views/generic/detail.py
names.append("%s/%s%s.html" % (
self.object._meta.app_label,
self.object._meta.object_name.lower(),
self.template_name_suffix
))
- elif hasattr(self, 'model') and hasattr(self.model, '_meta'):
+ elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model):
@akaariai
Django member
akaariai added a note May 27, 2012

why the is not None and issubclass check here instead of the normal isinstance?

@dstufft
Django member
dstufft added a note May 30, 2012

These views allow passing either a model or a queryset. self.model is not an instance of a model but the actual model class and thus isinstance won't work. The None check is that if self.queryset is used instead of self.model, self.model will be None and the first arg to issubclass must be a class, not None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@akaariai
Django member
akaariai commented Jun 8, 2012

Pulled in manually in commit 484fcd3. I removed the checks for isinstance(object_list, QuerySet) and retained the hasattr(object_list, 'model') instead because it seems lists containing attribute model are rare enough to not cause problems.

Thanks to dstufft for the patch! Unfortunately I forgot to thank him in the commit message, sorry for that.

@akaariai akaariai closed this Jun 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.