Skip to content

Instantly share code, notes, and snippets.

@rodrigoolmo
rodrigoolmo / geoPolymorphicManager.py
Created December 5, 2013 13:33
If you use GeoDjango your models require a GeoManager model manager. If you use django-polymorphic for inheritance in Django your models require a PolymorphicManager model manager. What if you need both functionalities? Then use this manager: GeoPolymorphicManager
from django.contrib.gis.db import models
from django.contrib.gis.db.models.query import GeoQuerySet
from polymorphic import PolymorphicManager
from polymorphic.query import PolymorphicQuerySet
class GeoPolymorphicQuerySet(GeoQuerySet, PolymorphicQuerySet):
'''
QuerySet used in GeoPolymorphicManager.
'''
@treyhunner
treyhunner / models.py
Created December 10, 2010 06:16
Encrypt and decrypt Django model primary key values (useful for publicly viewable unique identifiers)
# This code is under the MIT license.
# Inspired by this StackOverflow question:
http://stackoverflow.com/questions/3295405/creating-django-objects-with-a-random-primary-key
import struct
from Crypto.Cipher import DES
from django.db import models
def base36encode(number):