Django admin action 命令问题

CSDN问答 2022-09-09 02:18:13 阅读数:762

django问题命令adminaction

Django admin action 命令问题, 在admin添加action执行操作,没有反应

#admin模块class WareAdjustAdmin(admin.ModelAdmin): def custom_button(self, request, model_admin): """ 调整操作 :param request: :param object_id: :return: """ if request.POST.get('id'): with transaction.atomic(): for item in AdjustItem.objects.filter(master=self, status=0): inventory = item.inventory if item.prop == '+': inventory.cnt += item.cnt else: inventory.cnt -= item.cnt inventory.save() item.status = 1 item.event_time = datetime.datetime.now() item.source = self.code item.save() self.status = '9' self.execute_time = datetime.datetime.now() self.save()#下面是model模块class WareAdjust(models.Model): """ 库存调整 """ STATUS = ( ('0', '新建'), ('1', '进行中'), ('9', '已执行') ) index_weight = 4 code = models.CharField(max_length=120, blank=True, null=True, verbose_name='编号') # org = models.ForeignKey(Organization,verbose_name=_("organization"),blank=True,null=True) title = models.CharField(max_length=40, verbose_name='标题') description = models.TextField(blank=True, null=True, verbose_name='描述信息')  user = models.ForeignKey(User, verbose_name='使用人', blank=True, null=True, on_delete=models.SET_NULL, related_name=None) status = models.CharField(max_length=2, default='0', choices=STATUS, verbose_name='状态') execute_time = models.DateTimeField(blank=True, null=True, verbose_name='执行时间')class AdjustItem(InOutDetail): """ 库存调整明细 """ master = models.ForeignKey(WareAdjust, on_delete=models.CASCADE) inventory = models.ForeignKey(Inventory, blank=True, null=True, verbose_name='物资名称', on_delete=models.SET_NULL) def save(self, force_insert=False, force_update=False, using=None, update_fields=None): if self.inventory: self.material = self.inventory.material self.unit = self.inventory.unit self.warehouse = self.inventory.warehouse super(AdjustItem, self).save(force_insert, force_update, using, update_fields) def __str__(self): # 设置输出对象时的信息 return self.master.code class Meta: verbose_name = '库存调整' verbose_name_plural = verbose_nameclass InOutDetail(models.Model): """ in out detail """ PROP = ( ('+', '增加'), ('-', '减少') ) create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True) status = models.BooleanField(verbose_name='执行', default=0) event_time = models.DateTimeField(verbose_name='结束时间', blank=True, null=True) warehouse = models.ForeignKey(Warehouse, verbose_name='仓库', blank=True, null=True, on_delete=models.CASCADE) material = models.ForeignKey(Material, verbose_name='物资名称', blank=True, null=True, on_delete=models.CASCADE) unit = models.ForeignKey(Unit, verbose_name='计量单位', blank=True, null=True, on_delete=models.CASCADE) cnt = models.DecimalField(verbose_name='数量', max_digits=14, decimal_places=2, blank=True, null=True) batch = models.CharField(verbose_name='批次', max_length=20, blank=True, null=True) price = models.DecimalField(verbose_name='价格', max_digits=14, decimal_places=2, blank=True, null=True) prop = models.CharField(verbose_name='增加/减少', max_length=120, choices=PROP, default='+') source = models.CharField(verbose_name='来源', max_length=20, blank=True, null=True)
没用翻译
我想要达到的结果

在admin界面执行按键,实现表单的执行

img

版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7781181