我有以下 django 模型:
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…
以上是如何在 django 模型的 save 方法中获取当前用户?的详细内容。更多信息请关注PHP中文网其他相关文章!