django开发笔记2017-07-07
1、在开发中使用django中自带auth.user,如何获取当前操作的操作者即当前登录用户,那么通过以下方式可以获得:
import inspect
for frame_record in inspect.stack():
if frame_record[3] == 'get_response':
request = frame_record[0].f_locals['request']
break
else:
request = None
if request is not None:
instance.operator = request.user.username
2、django field关系关联其他model,在admin界面展示显示object,通过在model定义def __str__(self)方法可以展示你想要的数据。
def __str__(self):
return "%s %s"%(self.city_zh,self.county_zh)
您可能也对下面文章感兴趣:
There are 1 Comments to "django开发笔记2017-07-07"