Add your own field methods to Django's own user management

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.