djano

OneToOneField

场景:model 的扩展。

This is most useful as the primary key of a model which “extends” another model in some way

Model.get_absolute_url()

作用:程序或模版中调用避免硬编码。

场景:对象定义了该方法,则后台管理应用(admin app)中将增加一个 View on site 的链接,用于编辑对象时可以直接由后台跳转到对象的公共视图,以预览页面效果。

示例:

1
2
3
4
5
6
7
8
9
def (self):
from django.urls import reverse
return reverse('people.views.details', args=[str(self.id)])

def (self):
return "/people/%i/" % self.id

def __init__(self):
print('sdsa')