Django Contrib Model Field Extension

I have come across this situation several times.

If I have something that I usually like in contrib, but I want to make one small setting for the field, what should I do?

I do not want to throw the child in the bath.

To give an example, take auth.user (which, contrary to what seems to be a popular opinion on this issue, I think as usual on the right track). I want to create an end-to-end model for the relationship of auth.user to auth.group.

How can I do this without changing django?

+3
source share
1 answer

auth.User - , User Django, ( , ). , Django. , . svn update, svn diff svn patch, .

, Contrib, Python . , /, . , - (, , SO) , User Profile:

from django.db.models import Model
from django.contrib.auth.models import User

class UserProfile(Model):
    user = ForeignKey(User, unique=True)
    phone = CharField(verbose_name="phone number", blank=False, max_length='20')

User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

, / ModelFields django.contrib.auth.models.User.

, , UserProfile. , .

0

All Articles