Hi Anton,
You suppose correctly. :) None of the generic views combine an "object
detail" with "object list."
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
But it's very easy to pass in the object list as 'extra_context' to
the generic view, which I think people sometimes forget about.
Jay P.
In my opinion this is a must-know w.r.t. generic views.
Actually, IMO this should be the standard and recommended way of using
generic views instead of putting them into url.py. it is just cleaner
and more logical to keep all views (also generic ones) in the view.py
file.
regards
Terri
One thing that no one here has mentioned, and which the documentation
also does a poor job of mentioning (presumably because it explains
models before it explains templates, and thus doesn't want to get in to
template details when it explains model realtionships) is that if you
define relationships between objects, you can access related objects in
templates. For instance, let's say you have these models:
class UL(models.Model):
pass
class LI(models.Model):
UL = models.ForeignKey(UL)
name = models.TextField()
Using the object detail generic view on UL will give you an "object"
variable in your template for the given UL. This variable will have an
attribute (my terminology may be a little off here, but I'm too lazy to
look up the correct phrase, so just look at my examples if you're
confused): "li_set". This attribute in turn has two attributes: "all",
and "count". You can use these attributes to access the related LI's.
For instance, using:
{{ object.li_set.count }}
in your template will return the number of LI objects that have a
foreign key of this particular UL object's ID. Similarly, using:
{% for li in object.li_set.all %}
{{ li.name }}
{% endfor %}
will return the names of all of the LI's associated with this
particular UL object.
Hope that helps.
Jeremy