Re: Inherited classes and generic views - curiosity.

2008-10-23 Thread Malcolm Tredinnick


On Sun, 2008-10-19 at 12:29 -0700, Scott SA wrote:
> When passing a QuerySet of objects which inherit part of their model
> from another class, generic views only seems to respond to the parent
> class:
> 
> Here's a simplified example:
> 
> class ParentClass(models.Model):
> name_last = models.CharField(max_length=64)
> name_first = models.CharField(max_length=64)
> 
> class ChildClass(ParentClass):
> likes_spam = BooleanField(default=False)
> 
> Then, in the urls.py, I pass:
> {
> "queryset": ChildClass.objects.all()
> 
> }
> 
> Without specifying the template, generic views looks for
> "parentclass_list.html", not "childclass_list.html". 

That doesn't sound right. The model name is taken from the queryset's
model attribute, which will be ChildClass, and then the template name
will be ChildClass._meta.object_name.lower(), which will be
"childclass".

Which generic view are you calling that is exhibiting this behaviour? I
can't repeat it here and reading the code for a few random generic views
show that they're all doing the same thing when it comes to constructing
the template name.

Can you construct a short, complete example of two classes and a URL
pattern that demonstrates this problem?

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Inherited classes and generic views - curiosity.

2008-10-19 Thread Scott SA

When passing a QuerySet of objects which inherit part of their model
from another class, generic views only seems to respond to the parent
class:

Here's a simplified example:

class ParentClass(models.Model):
name_last = models.CharField(max_length=64)
name_first = models.CharField(max_length=64)

class ChildClass(ParentClass):
likes_spam = BooleanField(default=False)

Then, in the urls.py, I pass:
{
"queryset": ChildClass.objects.all()

}

Without specifying the template, generic views looks for
"parentclass_list.html", not "childclass_list.html". After specifying
which template to use, the ChildClass attributes are available via the
1:1 relationship so {{ object.childclass.likes_spam }} will retrieve
the desired attribute.

Where I've been caught with this is I'm inheriting from a generic
application that is not in my project directory. So not only was
django looking for parentclass_list.html and paentclass_detial.html,
it was looking for base_app/parentclass.html, etc.

I expected it to look in derived_app/childclass_list.html, etc.

Is this how this _should_ work, or should I post this to the developer
list and see what shakes?

Thanks,

Scott
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---