Re: is there a way to combine generic views?

2006-12-09 Thread machineghost

>> I want a page which displays both the details of an object and the list of
>> the objects.
Really important question: is the object you want the details of
related to the list of objects, via a ForeignKey or ManyToManyField?
Because if so, you don't need to do any view combination at all. (Of
course, if they are unrelated, everything everyone else said about
extending generic views is dead on).

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


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: is there a way to combine generic views?

2006-12-07 Thread Terji7


Condredge wrote:
> Hey Anton,
> Another option is to write a wrapper view that makes use of the generic
> views but adds more to it.  James Bennett over at B-List wrote a very
> useful article on this:
> http://www.b-list.org/weblog/2006/11/16/django-tips-get-most-out-generic-views

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


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: is there a way to combine generic views?

2006-12-07 Thread Condredge

Hey Anton,
Another option is to write a wrapper view that makes use of the generic
views but adds more to it.  James Bennett over at B-List wrote a very
useful article on this:
http://www.b-list.org/weblog/2006/11/16/django-tips-get-most-out-generic-views


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: Re: is there a way to combine generic views?

2006-12-07 Thread Jay Parlar

On 12/7/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> On 12/7/06, Anton Daneika <[EMAIL PROTECTED]> wrote:
> > I want a page which displays both the details of an object and the list of
> > the objects. Is there a known way to combine generic views to produce such a
> > thing? The problem is that all generic views return HttpResponse which I
> > don't need in that case -- just the processing.
> > I suppose it's just not the use case of the generic views -- they are not
> > for this.
>
> Hi Anton,
>
> You suppose correctly. :) None of the generic views combine an "object
> detail" with "object list."

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.

--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: is there a way to combine generic views?

2006-12-07 Thread Adrian Holovaty

On 12/7/06, Anton Daneika <[EMAIL PROTECTED]> wrote:
> I want a page which displays both the details of an object and the list of
> the objects. Is there a known way to combine generic views to produce such a
> thing? The problem is that all generic views return HttpResponse which I
> don't need in that case -- just the processing.
> I suppose it's just not the use case of the generic views -- they are not
> for this.

Hi Anton,

You suppose correctly. :) None of the generic views combine an "object
detail" with "object list."

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---