我还在学习如何使用Django2创建库存管理。你知道吗
我有接收用户输入并使用Django将其保存到数据库的模型。你知道吗
我想从填写表单的用户那里计算并获取总值。并希望在templates.html
中向用户显示结果
线索:
我需要从以下地方得到确切的总价:
total_product
*
per_unit_price
并将结果显示在:subtotal_unit_price
。
per_unit_price
*
profit_precent
(如果可能的话)除以100 %
,然后与per_unit_price
相加,结果在新字段中,可以是profit_bruto
。
profit_bruto
*
per_unit_product
结果将出现在:sell_price
。
正确的方法是什么?你知道吗
我被这件事困住了。你知道吗
models.py
"Stock Input"
class InputStock(models.Model):
number_product = models.AutoField(primary_key=True)
product_name = models.CharField(max_length=30)
total_product = models.IntegerField()
per_unit_product = models.IntegerField(blank=True)
per_unit_price = models.DecimalField(max_digits=14, decimal_places=2)
subtotal_unit_price = models.DecimalField(max_digits=14, decimal_places=2)
profit_percent = models.IntegerField()
sell_price = models.DecimalField(max_digits=14, decimal_places=2)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.nama_product
views.py
@login_required()
def InputStock(request):
form = InputStockForm(request.POST)
if request.method == 'POST':
if form.is_valid():
form.save()
form = DaftarBarangForm()
return render(request, 'input_data.html', {'form':form})
forms.py
class InputStockForm(forms.ModelForm):
class Meta:
model = InputStock
fields = '__all__'
我该如何处理这个问题?你知道吗
目前,表单仅将数据从(用户输入)保存到数据库。不算他们
你可以把你的逻辑放进去表单保存() 功能。只是像这样
相关问题 更多 >
编程相关推荐