python - How do I extend the Django Group model? -
You can extend a user, in addition to adding additional properties, a way to extend the built-in Django Group object Is objection? With the user object, you can do the following:
class UserProfile (models.Model): user = models.OneToOneField (user)
and Add
AUTH_PROFILE_MODULE = 'app.UserProfile'
to the Settings.py file that is:
Profile = user Objects.jet (id = 1) .get_profile ()
Is this group equal to this approach for the extension? If not, can I take an alternative approach?
You can create a model, group, add your own fields, and add any custom queries to Use the model manager to return. Here is a small example, which shows that I am expanding the group to represent families associated with a school:
from django.contrib.auth.models import groups, users Family Family Manager (models.Manager): "We set limited queries to families who currently enroll students, for example: Family: has_students.all ()" "def get_query_set (self): return super (Family Manager, Self) .get_query_set () Filter (student__enrolled = True). Distinction () class family (group): note = model TextField (empty = True) # Two manager for this model - first default # (hence all family administrators are visible). # The second call occurs only when we call the # family name has_students.all () objects = models Manager () has_students = FamilyManager () class meta: verbose_name_plural = "family" order = ['name'] def __unicode __ (self): back u '% s'% (self.name)
Comments
Post a Comment