我建立了一个django应用程序,该应用程序用于存储会议记录。工作室笔记对象称为StudioMeetingNote
,它具有2个CustomUser
模型的外键字段,即secretary
和chairman
。每个CustomUser
实例都有2个date
字段,即last_date_chairman
和last_date_secretary
。当以StudioMeetingNote
格式向用户分配主席后,我希望该用户的last_date_chairman
字段获得与分配给属于{{的字段meeting_start_date
的日期相同的值1}}本身。 StudioMeetingNote
也是如此。
为此,我决定使用last_date_secretary
方法。它位于def save_model
类中,该类代表admin部分中的StudioMeetingNoteAdmin
类。整个实现如下所示:
StudioMeetingNote
class StudioMeetingNoteAdmin(admin.ModelAdmin):
fields = (('meeting_start_time', 'meeting_end_time'), ('chairman', 'secretary'), 'absent_persons',)
# fieldsets = [
# ('Tijden', {'fields': ['meeting_start_time', 'meeting_end_time']}),
# ('Wie is de voorzitter/notulist', {'fields': [('chairman', 'secretary')]}),
# ('Opkomst', {'fields': [('attending_persons', 'absent_persons')]}),
# ]
inlines = [OpeningAndParticularitiesInline, ActionListPointInline, RemarksPriorMeetingInline, IssuesToAddressInline, OurNextMoveInline, QuestionRoundInline]
list_filter = ['meeting_start_time']
search_fields = ['meeting_start_time']
list_display = ('meeting_start_time', 'chairman', 'secretary')
save_as = True
def save_model(self, request, obj, form, change):
save_user = False
if 'chairman' in form.changed_data:
obj.chairman = form.cleaned_data['chairman']
obj.chairman.last_date_chairman = form.cleaned_data.get('meeting_start_date')
save_user = True
if 'secretary' in form.changed_data:
obj.secretary = form.cleaned_data['secretary']
obj.secretary.last_date_secretary = form.cleaned_data.get('meeting_end_date')
save_user = True
if save_user:
obj.save()
保存正确,但是当我查看用户指定的秘书/主席是否已更新其秘书/主席日期时,我可以看到没有更新发生。谁能告诉我我的studio note
代码有什么问题吗?
谢谢
编辑:这是完整的models.py文件
save_model