I try to make sure that when creating a record in the table, the current user is saved. There is a class
class SourceHistory(models.Model): source = models.ForeignKey(Source, verbose_name=u'Источник', null=False, blank=False) editor = models.ForeignKey(User, verbose_name=u'Пользователь', null=True, blank=True) Which in admin.py looks like this
@admin.register(SourceHistory) class SourceHistoryAdmin(admin.ModelAdmin): list_display = ('source', 'editor') def save_model(self, request, obj, form, change): obj.editor = request.user obj.save() Creating an object happens using the post_save signal.
@receiver(post_save, sender=Source) def source_save_history(sender, **kwargs): source = kwargs.get('instance') for f in source.memorized_fields: if source.__getattribute__(f) != source.memorized_fields[f]: sh = SourceHistory.objects.create( source=source ) Accordingly, now when creating an object, the editor field remains empty. Question: how to create a SourceHistory object so that the user is saved?