]> git.p6c8.net - pcdenotes.git/commitdiff
Automatically select the current user when creating a note
authorPatrick Canterino <patrick@patrick-canterino.de>
Sun, 6 Feb 2022 13:33:03 +0000 (14:33 +0100)
committerPatrick Canterino <patrick@patrick-canterino.de>
Sun, 6 Feb 2022 13:33:03 +0000 (14:33 +0100)
notes/admin.py

index 2dd4171e9e26ad0d7436d52a29b4d334121d2133..7272afb8854308d00d42ae28bb771a030b8908bd 100644 (file)
@@ -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

patrick-canterino.de