Skip to content

Instantly share code, notes, and snippets.

@niwinz
Created June 27, 2012 14:08
Show Gist options
  • Save niwinz/3004276 to your computer and use it in GitHub Desktop.
Save niwinz/3004276 to your computer and use it in GitHub Desktop.
Correct monky patching of django User.
# -*- coding: utf-8 -*-
from django.db.models import signals
def model_class_prepared(sender, **kwargs):
if sender._meta.app_label == 'auth' and sender._meta.module_name == 'user':
print "Monky patching user..."
email_field = sender._meta.get_field("email")
email_field.max_length = 200
email_field._unique = True
last_name = sender._meta.get_field("last_name")
last_name.max_length = 200
first_name = sender._meta.get_field("first_name")
first_name.max_length = 200
signals.class_prepared.connect(model_class_prepared)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment