Default value for user ForeignKey with Django admin
问题 author = models.ForeignKey(User) Is there any way I can set the default value of this field to automatically select the logged in user? I know you can do this in the save method but my client has requested that it automatically defaults to the logged in user at edit time to avoid confusion. This article goes into how to update it during save, just not at edit time. 回答1: class MyModelAdmin(admin.ModelAdmin): def formfield_for_foreignkey(self, db_field, request, **kwargs): if db_field.name ==