开发者

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开发者_StackOverflow中文版 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


You could subclass the User model and modify the fields you wish to extend, unfortunately it looks like the User model is hard-coded in django_auth_ldap so you'd then need to fork django_auth_ldap to use your custom User model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜