[patch] Implement `random` template tag
|Reported by:||Tom Tobin <korpios@…>||Owned by:||adrian|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
This patch implements a random template tag, doing for tag blocks what the random filter does for list items.
A random block begins with random and ends with endrandom; items are separated with or tags. Each possible tag block has an equal possibility of being selected, just as with the random filter.
I'm not sure or is an optimal separator tag for the random choices, but it was the best I've been able to come up with; suggestions for a superior tag name would be greatly appreciated.
I'm looking to additionally implement a "weighted" random option, which will allow one to specify unequal possibilities for random selection -- e.g., of two choices, the first is selected four times more often than the second. This will require a helper class, but I'm not certain which module it belongs in (perhaps django.core.extensions?).
Change History (13)
comment:7 Changed 7 years ago by korpios
- Reporter changed from Tom Tobin <korpios@…> to Tom Tobin <korpios@…>