Python Django Extending the existing User model with custom fields

Publicado em: 11 Junho 2014
no canal de: ATOM
11,134
21

Python Django Extending the existing User model with custom fields
http://fosshelp.blogspot.com/2014/06/...

1)

django-admin startproject mypro

django-admin startapp app1

2)

#vim mypro/app1/models.py

from django.contrib.auth.models import User

from django.db import models

class Employee(models.Model):

user = models.OneToOneField(User)

department = models.CharField(max_length=100)

3)

#vim mypro/mypro/settings.py

* add 'app1' in INSTALLED_APPS

4)

#cd mypro

#python manage.py syncdb

5)

#cd mypro

#python manage.py shell

>>> from django.contrib.auth.models import User

>>> u = User.objects.all()[0]

>>> u.employee

>>> u.empoyee.department

----------

>>> e = Employee()

>>> e.user = u

>>> e.department = "dddddd"

>>> e.save()

>>> u.employee


>>>
>>>
>>> u.employee.department
'dddddd'

----------


Nesta página do site você pode assistir ao vídeo on-line Python Django Extending the existing User model with custom fields duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário ATOM 11 Junho 2014, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 11,134 vezes e gostou 21 espectadores. Boa visualização!