# in file field.py
# adjust add_introspection_rules line as needed

from django.conf import settings

from django.db.models import CharField
import uuid

class UUIDField(CharField) :
    """
    UUIDField stored in 21 Chars
    Example: uuid = UUIDField(editable=False)
    """     
    def __init__(self, *args, **kwargs):
        kwargs['max_length'] = kwargs.get('max_length', 22 )
        # kwargs['blank'] = True
        kwargs['default'] = lambda: uuid.uuid4().bytes.encode('base64').rstrip('=\n').replace('/', '_')
        CharField.__init__(self, *args, **kwargs)
    
###################            
    
# South requires custom fields to be given "rules".
# See http://south.aeracode.org/docs/customfields.html
if "south" in settings.INSTALLED_APPS:
    try:
        from south.modelsinspector import add_introspection_rules
        add_introspection_rules([], ["extend\.fields\.UUIDField"])
    except ImportError:
        pass