From 9b36ee27357aaa8d1715b0a86db8cdd3f866c469 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sun, 6 Feb 2022 14:33:03 +0100 Subject: [PATCH 1/1] Automatically select the current user when creating a note --- notes/admin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/notes/admin.py b/notes/admin.py index 2dd4171..7272afb 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -9,4 +9,9 @@ class NoteAdmin(admin.ModelAdmin): search_fields = ('title', 'content',) prepopulated_fields = {'slug': ('title',)} + def get_form(self, request, obj=None, **kwargs): + form = super(NoteAdmin, self).get_form(request, obj, **kwargs) + form.base_fields['author'].initial = request.user + return form + admin.site.register(Note, NoteAdmin) \ No newline at end of file -- 2.34.1