I am looking for the exact same thing.


On Aug 6, 11:35 pm, bweiss <weissmanbia...@gmail.com> wrote:
> Is there a simple way to do the following that I'm just not seeing, or
> am I looking at trying to write a custom tag?  The functionality I
> need is similar to {% regroup %} but not quite the same...
>
> My app currently has a custom admin view in which I've defined a whole
> bunch of different lists, which are all objects of the same model,
> filtered according to different options of a field called "Type".
> (eg. type_A_list = mymodel.objects.filter(Type="A"); type_B_list =
> mymodel.objects.filter(Type="B"); etc.)
>
> I've realised that the number of database hits this involves is
> inefficient, and it would be cleaner to have a single list of objects
> and try to perform the logic I need at the template level.
>
> What I'd like to be able to do is, for a single variable,
> "object_list", define subsets of this list containing objects that
> meet a certain condition.  So, to filter by the field "Type", I could
> define lists called "type_A_list", "type_B_list", etc, that could be
> iterated through in the same way as the original list.
>
> The reason I need to do this is to be able to use the {% if
> type_A_list %} tag in order to flag when there are NO objects of a
> given type.  This is why (as far as I can see) the {% regroup %} tag
> won't quite work, as it only lists the groups that actually have
> members.
>
> Output would look something like:
>
> Type 1:
> Object 1, Object 5, Object 6
>
> Type 2:
> There are no objects of Type 2
>
> Type 3:
> Object 2, Object 4
>
> Does anyone have any suggestions?
>
> Thanks,
> Bianca
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to