Allow for larger field sizes and truncation when using Django auth LDAP backend
I'm using django_auth_ldap.backend.LDAPBackend to authenticate users against a LDAP directory and copy some attributes from LDAP (cn, sn, email, etc). However, some LDAP fields have larger values than the django.auth.models.User model supports.
How can I instruct Django to use bigger max_length values for the User model?
<< Update >>
I already found the solution. I've put the following lines in models.py of my application, before doing the first syncdb:
Hack django.contrib.auth.User
User._meta.get_field_by_name('username')[0].max_length = 128 User._meta.get_field_by_name('first_name')[0].max_length = 128 User._meta.get_field_by_name('last_name')[0].max_length = 128 User._meta.get_field_by_name('email')[0].max_length = 128
您可以对用户模型进行子类化并修改您希望扩展的字段,不幸的是,它看起来像用户模型在django_auth_ldap中进行了硬编码,因此您需要分叉django_auth_ldap以使用您的自定义用户模型。
链接地址: http://www.djcxy.com/p/33742.html上一篇: 从Django模型过滤json数据