This class generates a crows-foot notation ERD for your models (currently does not include fields) using GraphViz. The cardinality/modality of the relationships isn't perfect, but it works for 99% of cases out there.
Add the line shown, or something similar, to your settings/dev.py, so that you can more clearly see when django is silently hiding errors in your template tags.
This snippet parses the output file of inspectdb and does some alterations. Mostly useful for people who regenerates models from constantly changing legacy databases.
The snippet will:
*Add quotes around foreign key classes, so the ordering is not significant
*Append a related_name property to each foreign key with the value
model class name + db_column name to evade collisions in reverse queries like:
example.model: Reverse query name for field 'foreignkey' clashes with related field 'model2.foreignkey'. Add a related_name argument to the definition for 'foreignkey'.
There's a slight performance degradation with using quotes class name instead of passing the class though.
A mixin to define permissions on models. This is more of an abstract model to subclass/customise than a plug-in solution. Explanations are [here](http://www.muhuk.com/2009/05/django-permission-system/).
A simple template filter for breaking a list into sublists of a given length, you might use this on an ecommerce product grid where you want an arbitrary number of rows of fixed columns. Unlike the other partitioning filters I've seen, this doesn't try to distribute the rows evenly, instead it fills each row for moving onto the next.
This filter preserves the ordering of the input list.
This commands runs a Python interactive interpreter with test database and data from the given fixture(s). It is usable if you want to play with test database.
See also testserver docs
Just a quick tip on how to use the pyfacebook django middleware as a decorator since you probably dont want to add the facebook object to all incoming requests.
This code monkey-patches the default User model to rather use a primary key of UUIDField (see http://www.djangosnippets.org/snippets/1496/). This code also makes the email field required. This code is wildly dangerous, not completely future proof, and probably not advisable to use. If you do wish to use it, it will be easiest to implement on a fresh db with a syncdb. If you need to migrate existing user data the onus is on you to figure out an appropriate db migration plan.
I placed this code in a models.py, but it is probably more reliably placed in urls.py
This snippet updates http://www.djangosnippets.org/snippets/383/ for Django 1.0+, and adds support for sqlite3.
Original snippet text:
A CompressedTextField to transparently save data gzipped in the database and uncompress at retrieval.
Generate QR Code image from a string with the Google charts API
http://code.google.com/intl/fr-FR/apis/chart/types.html#qrcodes
Exemple usage in a template
{{ my_string|qrcode:"my alt" }}
will return the image tag with
* src: http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=my_string&choe=UTF-8
* alt: my alt"
This cache_page decorator can be used in replacement to Django's django.views.decorators.cache.cache_page.
It resolves two problems:
- invalidation (its cache key is not dependent of header nor request, then you can use model signals (or method 'put' in Google App Engine) to invalidate a URL or a list of them)
- easier to scale (can be used at once memcached server by many differente servers)
Feel free to show me where it can have problems or limitations.
**Updated and improved a lot**
A simple jQuery javascript that collapses all stacked inline rows for better handling of large inline fieldsets.
It also adds "Show"/"Hide"-buttons for showing/hiding each row, which could be customized and styled using css.
**Usage (see below for example):**
Include the javascript on your admin page, together with jQuery, and it'll automatically affect all stacked inlines.
**Developed for:**
* jQuery 1.3.2
* Django trunk (tested in Django v1.0.2)
* (Might work with other versions with or without adjustments, but not tested)
**Use example: **
*admin.py:*
class DateInline(admin.StackedInline):
model = Date
extra = 10
class EventAdmin(admin.ModelAdmin):
inlines = [DateInline]
class Media:
js = ['js/jquery-1.3.2.min.js', 'js/collapsed_stacked_inlines.js',]
admin.site.register(Event, EventAdmin)