This is another foreign key to User model. User is automatically associated before save.
Requires: [ThreadlocalsMiddleware](http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser)
Inspired by: [snippet 509](http://www.djangosnippets.org/snippets/509/)
Many of my projects heavily depend on other non-django projects to create the databases. To simplify setting up a test environment, I modified the simple test runner so that it will treat all models as managed.
This will also allow for easier test set up against models that point to views. You can directly populate the view with the specific data needed for the tests, instead of populating (potentially) several models.
This example shows, how to use database views with django models. NewestArticle models contains 100 newest Articles. Remember, that NewestArticle model is read-only. Tested with mysql.
With these models, you can use your Django's database directly as backend for PowerDNS server (tested with MySQL).
License: GNU GPL.
More info:
http://downloads.powerdns.com/documentation/html/configuring-db-connection.html#CONFIGURING-MYSQL
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/).
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.
This is a custom field that lets you easily store JSON data in one of your model fields. This is updated to work with Django 1.1.
**Example: (models.py)**
from django.db import models
import JSONField
class MyModel(models.Model):
info = JSONField()
** Example: (shell)**
>>> obj = MyModel.objects.all()[0]
>>> type(obj.info)
<type 'NoneType'>
>>> obj.info = {"test": [1, 2, 3]}
>>> obj.save()
**[Code at GitHub](http://github.com/bradjasper/django-jsonfield/tree/master)**
I wanted to store ipv4 and ipv6 ip's in django but I wanted to use the postgresql inet network field type:
http://www.postgresql.org/docs/8.3/static/datatype-net-types.html
and I wanted to use IPy.py IP objects in python. I followed these very helpful examples along with the django documentation:
http://vaig.be/2009/03/numeric-ip-field-for-django.html
http://www.djangosnippets.org/snippets/1381/
It took me awhile to figure out how this works (not that I completely understand it now..) and figured I would share it. If anyone finds problems with this or can make it better I will definitely use it.
Example mixin for creating and removing thumbnails on a model. Also adds some methods for accessing an url for an image size. It might be a better idea to use a custom image field instead of this approach.
Idea for getting the image url for different sizes from http://code.google.com/p/django-photologue
Example usage
<pre>
>>> p.get_small_image_url()
u'http://127.0.0.1:8000/site_media/photos/small_someimage.jpg'
</pre>