[Answered ]-Use logged in username as field value in django

2👍

You can use User model as foreign key in the LineItem model as buyer.Whenever you are saving data in LineItem model, in that view,you can get request.user as the logged in user and store it as the buyer of that LineItem Object.

In LineItem model class

buyer = models.ForeignKey(User)

In the view class/function of creating/updating a Lineitem object (in the post method) you can do

a_lineitem_object.buyer = request.user
a_lineitem_object.save()

Leave a comment