"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to get current user in save method of a django model?

How to get current user in save method of a django model?

Published on 2024-08-15
Browse:930
How to get current user in save method of a django model? How to get current user in save method of a django model?
How to get current user in save method of a django model?
0
How to get current user in save method of a django model?

I have the following django model:

class Listing(models.Model)
    STATUS_CHOICES = [
        ('available', 'Available'),
        ('rented', 'Rented'),
        ('unavailable', 'Unavailable'),
        ('fake', 'Fake'),
    ]

    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=200)
    description = models.TextField()
    status = models.CharField(max_length=12, choices=STATUS_CHOICES, default='available')
    def save(self, *args, **kwargs):
        ## 
        if self.status == 'fake' and  ......:
            raise PermissionDenied("Cannot save listing with
Open Full Question
Release Statement This article is reproduced at: https://dev.to/mirzonabot/how-to-get-current-user-in-save-method-of-a-django-model-1d47?1 If there is any infringement, please contact study_golang@163 .comdelete
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3