python - Use logged in username as field value in django -
How do I use the user's username as the default (and editable) value in the Django field?
For example, let's say that I'm trying to log in to the item purchased by a team of people I am using contrib.admin
because it's my I fulfill the most needs, I define the line item purchased like this:
I have this code & amp; Something wrong with the name of the logged-in user?
PS I think there is another way in accordance with this question: where continuity of view-> database should I get the name of the user and store it?
You use the user model as a buyer in the line model as a buyer in the form of a foreign key can do. Whenever you are saving data in the line item model, in that view, you can get request.user as a logged in user and store it. As the buyer of that line item object
Create a lineitum object (in the post method) in the lineItem model class
buyer = models.ForeignKey (user)
To see / update the class / function, you can
a_lineitem_object.buyer = request.user a_lineitem_object.save ()
Comments
Post a Comment