Widget for editing CommaSeparatedIntegerField with a set of checkboxes. Each checkbox corresponds to single integer value. So, choices should be pre-defined for widget.
**Example**
Assume, we need a registration form for some event with time frame for 3 days, starting at Monday. User can select any of 3 days, so we need to show 3 checkboxes.
Here's the basic example for such form:
class EventRegistrationForm(forms.Form):
days = forms.CharField(widget=NumbersSelectionWidget(
['Mon', 'Tue', 'Wed'], range(1, 4)))
- forms
- widget
- comma-separated
An example of how to select the "default" database based on the request URL instead of the model. The basic idea is that the middleware `process_view` (or `process_request`) function sets some context from the URL into thread local storage, and `process_response` deletes it. In between, any database operation will call the router, which checks for this context and returns an appropriate database alias.
In this snippet, it's assumed that any view in the system with a `cfg` keyword argument passed to it from the urlconf may be routed to a separate database. Take this urlconf for example:
`url( r'^(?P<cfg>\w+)/account/$', 'views.account' )`
The middleware and router will select a database whose alias is `<cfg>`, or "default" if none is listed in `settings.DATABASES`, all completely transparent to the view itself.
- multidb database router url
http://github.com/coleifer/django-generic-aggregation
http://charlesleifer.com/blog/generating-aggregate-data-across-generic-relations/
Generate and calculate aggregations across generic foreign keys.
>>> from misc import generic_annotate, generic_aggregate
>>> from blog.models import Entry
>>> from tagging.models import TaggedItem
>>> from django.db.models import Count
>>> qs = generic_annotate(Entry.objects.all(), TaggedItem.object, 'id', Count)
>>> qs[0].score
5L
>>> qs[1].score
4L
>>> qs[1].tags
u'databases django many-to-many python'
>>> generic_aggregate(Entry.objects.all(), TaggedItem.object, 'id', Count)
106L # total number of times entries were tagged