BooleanField that treats '0' as unchecked
Helpful for maintaining state of a BooleanField in the querystring, eg. checkbox=0 / checkbox=1
- BooleanField
Helpful for maintaining state of a BooleanField in the querystring, eg. checkbox=0 / checkbox=1
If you are interested to use Ext JS 4 with Django take a look of the project that I created: https://github.com/TofPlay/django-easyextjs4
As it took me a save option name instead of its value. This field are solves this rare problem.
Just a quick and dirty solution I needed to uniquely color code entries in a selection form list. It uses the hashlib to generate it's coloring.
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.
When developing a site, I sometimes want to be able to visually reference the HTML before it's given a real context, and a view. This extra bit of code will allow you to add a directory within your templates dir, and pull any html files and subdirectories from it. I added the if statement to automatically use an index.html file if there's no file and extension at the end. You can substitute anything you like for the "html" in "(?P<base>html)". That's just passed as an argument to prepend to the template as a base directory for the templates.
Memcached Property Attributes ----------------------------- Setting the attribute will store the value in memcached; accessing the attribute will retrieve from memcached. Most useful as a way of simulating memcached "fields" on model instances. See the docstring for details.
Django admin orders models by their primary key by default, which can be undesirable on very large tables. This shows how to disable any ordering on a model. Note that this behavior is fixed in 1.4 trunk.
Save method, useful for automate pdf files creation if you want to use the file in database.
Tag for simple embed video from youtube watch link. It can be modified to manage size of embedded video.
A project I'm working on requires multiple different classes of users, all with different fields/attributes. Having a single UserProfile class with a generic relation was a complete pain in practice. So, I changed my classes to all subclass User directly and then used django-model-utils to create a custom ModelBackend that returns the appropriate class when accessing request.user. The InheritanceQuerySet manager provided by django-model-utils makes it all possible and with only a single database query. No need to add anything directly to the User class, by the way. Just subclass it directly with each of your custom classes: class CustomUser1(User): field1 = models.CharField(...) class CustomUser2(User): field2 = models.CharField(...)
Instead of creating a dictionary on every view everytime you could do this and just call it like c = create_c(request)
This is a modification of Django 1.3's transaction.commit_on_success() decorator and context manager. It's inspired by snippet [1343](http://djangosnippets.org/snippets/1343/) which unfortunately don't work in current Django neither as a context manager. In my junior projects it works fine but I've not tested in critical projects yet! YMMV ! How it works: it simply counts the nesting level and does the real transaction enter/exit only on first call and last call respectively (code copied from Django's commit_on_success() ). It use thread local storage to save the per-thread nesting level count safely. To use it just put the code in a file (i.e. nested_commit_on_success.py) and import and use it exacly as normal commit_on_success(), both as decorator (@nested_commit_success) or context manager (with nested_commit_on_success(): ). Any feedback is welcome!
See code
Needed a function to check if any field in an instance has changed. If so update a datetime field to now to keep track of changes. This function is an override of the save function in the model.