Login

Top-rated snippets

Snippet List

Custom Times for the Django Admin Time Widget

Based on code from [mihelac.org](http://source.mihelac.org/2010/02/19/django-time-widget-custom-time-shortcuts/) Modified to work in Django 1.3.1. Put it in templates/admin/app_label/model/change_form.html

  • template
  • javascript
Read More
Author: caa
  • 0
  • 1

Decorate every view in a url tree

Add login_required (or any other combination of decorators) to any view references by the urls created by patterns(...). My personal little itch as an example... urlpatterns += required( login_required, patterns('', (r'^api/', include(api.urls)), ) )

  • urls
  • login_required
Read More

Active Directory Authentication Backend (with User object updating)

I used the code from http://djangosnippets.org/snippets/901/ and expanded the code to have the possibility to map AD groups to the superuser attribute of Django's users. The code updates the Django users database every time a user connects, so every change in the AD is replicated to the Django database.

  • Active Directors
  • Auth
Read More

staff_or_404 Decorator

Sometimes I don't want to reveal a staff-only view so I created this decorator, using ``django.contrib.admin.views.decorators.staff_member_required`` as my boilerplate. Non staff members are kicked to the 404 curb. Suggestion: Create a file, ``decorators.py`` in your project (or single app) and import like so: ``from myproject.app_name.decorators import staff_or_404``.

  • user
  • auth
  • decorators
  • staff
Read More

Exists Filter OneToOneField in Admin

Adds Boolean like Filter in Admin to OneToOneField reference. Allowing to filter in the Parent for instances without Referenced Field. To register the filter, import in `urls.py` for example: import filterspecs Example `models.py`: from django.db import models class Place(models.Model): name = model.CharField(maxlength=50) address = model.CharField(maxlength=80) class Restaurant(meta.Model): place = model.OneToOneField(Place) place.exists_filter = True serves_hot_dogs = model.BooleanField() serves_pizza = model.BooleanField() Example `admin.py`: from django.contrib import admin from models import * class PlaceAdmin(admin.ModelAdmin): list_filter = ('restaurant',) admin.site.register(Place, PlaceAdmin) With this example PlaceAdmin will have a filter: By Restaurant All Yes No Where `Yes` will list `Place` with `Restaurant` instances, and `No` will list `Place` without `Restaurant` instances.

  • admin
  • filters
  • OneToOneField
Read More

Choice Submit Widget

This widget renders choices as submit buttons. This may be a better choice than radio buttons + submit sometimes

  • choices
  • widget
  • submit
Read More

3110 snippets posted so far.