detail_route 到底是那个包里的呀!
我想要覆盖Django xadmin 的post提交
因为提交的内容有部分需要加入缓存!
xadmin提交时将,‘房间’,‘柜子’,‘传感器’,等加入缓存。
怎末做呀!有偿
下面是模型:
class CabinetContent(models.Model):
cabinet_content_id = models.AutoField("柜子详细信息ID", primary_key=True)
SwitchRoom_id = models.ForeignKey(SwitchRoom, verbose_name='房间', null=True, on_delete=models.CASCADE)
cabinet_id = models.ForeignKey(Cabinet, verbose_name='柜子', blank=True, null=True, on_delete=models.CASCADE)
sensor = models.ForeignKey(Sensor, verbose_name='传感器', blank=True, null=True, on_delete=models.CASCADE)
temperature_testing_position_num = models.CharField('温度检测位置编号', max_length=255, blank=True, null=True)
electric = models.IntegerField('电量', blank=True, null=True)
average = models.IntegerField('平均值', blank=True, null=True)
max = models.IntegerField('最大值', blank=True, null=True)
threshold = models.IntegerField('阈值', blank=True, null=True)
pulse_number = models.IntegerField('脉冲数', blank=True, null=True)
Tropism = models.IntegerField('向位', blank=True, null=True)
number = models.IntegerField('温度', blank=True, null=True)
monitoring_frequency = models.CharField(default=default_department(), verbose_name='监测密度', max_length=20, null=True)
early_warning = models.CharField('预警', max_length=255, blank=True,
null=True) # Field renamed to remove unsuitable characters.
add_people_id = models.IntegerField('传感器添加人', blank=True, null=True)
add_sensor_time = models.DateTimeField('传感器添加时间 ', blank=True, null=True)
sensor_position = models.ForeignKey(SensorPosition, verbose_name='传感器位置', on_delete=models.CASCADE)
remarks = models.CharField('备注', max_length=255, blank=True, null=True)
class Meta:
db_table = 'cabinet_content'
verbose_name_plural = "柜子详细信息"
unique_together = ('cabinet_content_id', 'SwitchRoom_id', 'cabinet_id', 'sensor')
def save_models(self):
obj = self.new_obj
request = self.request
SwitchRoom_id = request.POST['SwitchRoom_id']
cabinet_id = request.POST['cabinet_id']
sensor = request.POST['sensor']
temperature_testing_position_num = request.POST['temperature_testing_position_num']
electric = request.POST['electric']
average = request.POST['average']
max = request.POST['max']
threshold = request.POST['threshold']
pulse_number = request.POST['pulse_number']
Tropism = request.POST['Tropism']
number = request.POST['number']
monitoring_frequency = request.POST['monitoring_frequency']
early_warning = request.POST['early_warning']
add_people_id = request.POST['add_people_id']
add_sensor_time_0 = request.POST['add_sensor_time_0']
add_sensor_time_1 = request.POST['add_sensor_time_1']
sensor_position = request.POST['sensor_position']
remarks = request.POST['remarks']
creap = []
sql = 'select sensor_type_id_id,sensor_num from sensor where sensor_id=' + sensor + ';'
date = sql_db.get_all(sql)
print(date[0][0])
sql = 'select sensor_type from sensor_type where sensor_type_id=' + str(date[0][0]) + ';'
date = sql_db.get_all(sql)
creap.append(date[0][0])
creap.append('POST')
creap.append(sensor)
try:
creap.append(Tropism) # id
except:
creap.append(0)
connrd2 = redis.Redis(connection_pool=rd2)
try:
cc = connrd2.get(SwitchRoom_id).decode('utf-8')
cc = eval(cc)
cc.append(creap)
connrd2.set(SwitchRoom_id, json.dumps(cc))
except:
cc = []
cc.append(creap)
connrd2.set(SwitchRoom_id, json.dumps(cc))
obj.save() # 改变表ip_address要保存
admin
– 剧毒是对的 3年前提交时做增加处理我是会的用save_model可以做过滤
xadmin没有这个方法,就不会了