我详细介绍了我的代码:我不知道为什么我的表是空的(似乎在调用后它是空的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)