#coding =utf-8from django.db Import modelsfrom django.contrib.auth.models import User, Make_password, Check_password, Group, groupmanagerfrom django.contrib.auth.admin import useradminfrom onlineanswer.settings import uploadto# Create Your models Here.class webpowers (models. Model): Powername = models. Charfield (MAX_LENGTH=250) def __unicode__ (self): return self.powernameclass ProfileBase (type): #对于传统类, their meta-classes are types. ClassType def __new__ (CLS, name, bases, attrs): #带参数的构造器, __new__ generally used to set subclasses of immutable data types module = Attrs.pop (' __modul e__ ') parents = [B for B in bases if Isinstance (b, ProfileBase)] if parents:fields = [] For Obj_name, obj in Attrs.items (): If Isinstance (obj, models. Field): Fields.Append (obj_name) user.add_to_class (obj_name, obj) useradmin.fieldsets = List (User Admin.fieldsets) UserAdmin.fieldsets.append ((name, {' Fields ': Fields})) return super (ProFileBase, CLS). __new__ (CLS, name, bases, Attrs) class Profileuser (object): __metaclass__ = ProfileBase #类属性class MyP Rofile (profileuser): Headimage = models. ImageField (Upload_to=uploadto, Null=true, Blank=true, verbose_name= "Avatar")
Add your own field methods to Django's own user management