Access to request.user from Django model
📁 method, Advanced Python Topics, django
I'm writing a site on Django. There is a problem: There is a Client model, and for almost everywhere on the site, the user needs to display their clients. At first, I wrote in each view like this:
Client.objects.filter(user=request.user)Then I created my own Manager with a method that requires passing the user, but overall this does not solve the problem of constantly passing the user. How can I make the current user accessible in models.py?
The problem is solved using MIMEText
The solution was found here
Thank you
# -*- coding: utf-8 -*-""""""Send email via smtp_host.""""""import smtplibfrom email.mime.text import MIMETextfrom email.header import Headersmtp_host = 'smtp.gmail.com' # yahoologin = ""xxxxxx@gmail.com""password = ""xxxxxxx""recipients_emails = ""xxxxxx@gmail.com""msg = MIMEText('Thank you', 'plain', 'utf-8')msg[ Log in to leave an answer