-1

I have a django model "Post" that has a field:

author = models.ForeignKey('auth.User')

I also have a PostForm in forms.py with author as a field and Post as the model. I want to only show the user logged in and not all superusers.

https://gyazo.com/fb8884391bdf8284065175fbcdc16f75

Is there a painless way of doing so? If not what is my best option?

Justin Smith
  • 173
  • 2
  • 9

1 Answers1

2

From a high level, you'll need to handle it in the __init__ method of the form. After you call super, change the queryset on the author field of the form and set it to the request's user.

schillingt
  • 13,493
  • 2
  • 32
  • 34