How to auto insert the current user when creating an object in django admin?

前端 未结 5 2082
别跟我提以往
别跟我提以往 2020-12-08 01:08

I have a database of articles with a

submitter = models.ForeignKey(User, editable=False)

Where User is imported as follows: <

5条回答
  •  一生所求
    2020-12-08 01:22

    As per http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields you can't use ForeignKey with the prepopulated_field admin directive, alas

    But this thread might help you. In my answer I also link to a Google-scanned version of Pro Django, which has a great solution for this kind of thing. Ideally, am sure it's better if you can buy the book, but Google seems to have most of the relevant chapter anyway.

提交回复
热议问题