【发布时间】:2009-08-31 10:06:54
【问题描述】:
我提供了我的代码的详细信息:我不知道为什么我的桌子是空的(在调用save_model 之后它似乎是空的,但我不确定)。
class PostAdmin(admin.ModelAdmin):
def save_model(self, request, post, form, change):
post.save()
# Authors must be saved after saving post
print form.cleaned_data['authors'] # []
print request.user # pg
authors = form.cleaned_data['authors'] or request.user
print authors # pg
post.authors.add(authors)
print post.authors.all() # [<User: pg>]
# But on a shell, table is empty. WTF ?! :
# select * from journal_post_authors;
# Empty set (0.00 sec)
【问题讨论】:
-
django 管理视图发生在事务中,如果抛出异常则回滚。结果页面是否正常呈现?另一种可能性可能是我们都碰巧犯的一些错误:您是否在 shell 会话中查询了正确的数据库?数据库是否可以被 django 进程写入?
标签: python django save add manytomanyfield