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'
----------
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'
----------
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-user
ReplyDeleteWhat about django form and processing it with a single view?
ReplyDelete