保存管理表单后,如何更新用户的日期字段?

时间:2019-11-29 15:43:28

标签: django django-models django-forms django-admin

我建立了一个django应用程序,该应用程序用于存储会议记录。工作室笔记对象称为StudioMeetingNote,它具有2个CustomUser模型的外键字段,即secretarychairman。每个CustomUser实例都有2个date字段,即last_date_chairmanlast_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

0 个答案:

没有答案