class Room(models.Model):
a = models.PositiveIntegerField(default=0, validators=[MaxValueValidator(9)],blank=True)
b = models.PositiveIntegerField(default=0, validators=[MaxValueValidator(99999)],blank=True)
c = models.PositiveIntegerField(default=0, validators=[MaxValueValidator(9999)],blank=True)
@property
def cal_room_rent(self):
if self.room_type == 'SS' :
return 14000
elif self.room_type == 'DS' :
return 8000
elif self.room_type == 'TS' :
return 6000
@property
def cal_security_deposit(self):
return 3000
@property
def cal_limit(self):
if self.room_type == 'SS' :
return 1
elif self.room_type == 'DS' :
return 2
elif self.room_type == 'TS' :
return 3
def save(self, *args, **kwargs):
self.a=self.cal_limit()
self.b=self.cal_room_rent()
self.c=self.security_deposit()
super(Room, self).save(*args, **kwargs)
OUTPUT:
TypeError at /admin/pgmanagement/room/add/
'int' object is not callable
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/pgmanagement/room/add/
Django Version: 2.1.4
Exception Type: TypeError
Exception Value:
'int' object is not callable
Exception Location: E:\anil_website\svcomforts_1\pgmanagement\models.py in save, line 93
你有这个错误,因为cal_limit
,cal_room_rent
,security_deposit
返回一个int对象,你试图调用它。试试这个:
def save(self, *args, **kwargs):
self.a=self.cal_limit
self.b=self.cal_room_rent
self.c=self.security_deposit
super(Room, self).save(*args, **kwargs)