编辑为使用一对一字段
我想将建筑物的面积添加到 django modeladmin 中。表结构是
class Area(models.Model):
id= models.IntegerField('Buildings', db_column='id')
area=models.FloatField(blank=True, null=True)
class Buildings(models.Model):
id = models.AutoField(primary_key=True)
auto_sf = models.OneToOneField(Area, db_column='id')
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过使用访问区域属性
b=buildings.get(id=1)
print(b.area.area)
Run Code Online (Sandbox Code Playgroud)
但我不明白如何将 b.area.area 合并到 modeladmin 中 - 因为这不起作用。
class AdminSection(admin.ModelAdmin):
def area(self, obj):
return obj.area.area
fields=(('id','area'))
Run Code Online (Sandbox Code Playgroud) 我试图了解此Python 2.7.5示例脚本的输出:
import time
from multiprocessing import Pool
print(time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())))
props2=[
'170339',
'170357',
'170345',
'170346',
'171232',
'170363',
]
def go(x):
print(x)
if __name__ == '__main__':
pool = Pool(processes=3)
pool.map(go, props2)
print(time.strftime('%Y-%m-%d %H:%M', time.localtime(time.time())))
Run Code Online (Sandbox Code Playgroud)
这产生输出:
2015-08-06 10:13
2015-08-06 10:13
2015-08-06 10:13
170339
170357
170345
170346
171232
170363
2015-08-06 10:13
2015-08-06 10:13
2015-08-06 10:13
我的问题是:
A)为什么时间在开始和结束时打印三遍?我希望它能打印开始时间,然后打印结束时间。
B)真正的问题-如何使它多次运行一个命令,而一次运行所有其他命令?