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

WBOY
發布: 2024-08-12 18:45:13
原創
505 人瀏覽過
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

以上是How to get current user in save method of a django model?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!