Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

0
Adding logged in username as a field to a model in Django 2.0+
Post Body

I am new to Django and trying to learn how to build websites by playing around with a small project of my own.

How can I add the current logged in username as a field named "added_by" in my model? Below is my example model for reference. I have spent the last several hours trying to get this to work but in vain. I am looking forward to your help and support as I am currently clueless about this step.

UPDATE: Just to give a simple explanation, I am trying to create a simple Phonebook where a user can signup and login (required), add/update/delete contacts. For that I have created two apps - contacts and users. The contacts app handles everything related to adding/deleting/updating a user's contacts for which I have created a Contact model. The users app handles everything related to sign up, login and logout and I have created a separate Profile model for it.

Currently, the sign ups, logins and logouts work well. I am also able to add new contacts to my profile after signing in too. But the problem is, I am seeing contacts added by all users and not specific to the ones only I added. For this very reason, I want to add a username column to the Contact Model using which I can filter out all contacts relative to the person who has signed in. Hope this gives some clarity on what I am doing.

P.S. I am new to Django. This is just my learn on the job kind of project. Kindly bear with me if I do not understand everything.. :-)

Django Model

Author
User Disabled
Account Strength
0%
Disabled 4 months ago
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
6,531
Link Karma
663
Comment Karma
5,737
Profile updated: 4 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago