I'm still learning how to create Inventory Management by using Django2.
I have models that receive user input and save it to the database using Django.
I want to calculate & get the total value from the user who fills up the form. And want to show the result to the user in the templates.html
Clue :
I need to get the exact total price from:
total_product
*
per_unit_price
and show the result in:subtotal_unit_price
.per_unit_price
*
profit_precent
(in % if possible) and divide by100 %
and then sum / added up withper_unit_price
, the result are in the new field which is can beprofit_bruto
.profit_bruto
*
per_unit_product
and the result will be in:sell_price
.
What is the right way to approach this?
I'am stuck with this documentation.
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__'
How do I approach this?
Currently, the form is only saved the data from (user input) to the database. not calculate 'em.