django 我有一个类,它包含一个名为available的变量和其他isActive变量

kq0g1dla  于 2023-01-21  发布在  Go
关注(0)|答案(1)|浏览(108)

我刚开始在django。我有一个类与一个变量称为available = models.CharField(max_length=20)和其他isActive = models.BooleanField(default=True)。默认情况下,变量available获得的值“available”。我希望能够得到字“unavailable”在available字段,如果isActiveFalse。谢谢

def availibility (request, id): 
  listingData = Listing.objects.get(pk=id) 
  if listingData.isActive == False: 
  listingData.available = "unavailable" 
  listingData.save() return 
  render(request, "auctions/watchlist.html")
5ssjco0h

5ssjco0h1#

listingData = Listing.objects.get(pk=id)    
if listingData.isActive == False:
    listingData.available = "unavailable"
    listingData.save()

相关问题