V
V
Vladimir2019-05-15 07:23:17
Django
Vladimir, 2019-05-15 07:23:17

How to handle data from model in views?

class QuantityComponent(models.Model): #подсчитанные компоненты к прибору
  part_number = models.ForeignKey(Component, on_delete=models.CASCADE)
  quantity = models.IntegerField('quantity', null=True, blank=True)
  def multiple(self):
      summ = self.quantity * 5
      return summ

def countspecification(request, device, multiple):
    context = {}
    quantityGroupComponentsForDevice = QuantityComponent.objects.filter(groupcomponents__name__contains = device)
    context['result'] = quantityGroupComponentsForDevice
    return render(request, "groupcomponents.html", context)

It is necessary to self.quantity
multiply the value by the passed parameter from the request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2019-05-18
@QuixTag

The problem is solved by overriding the save() method of the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question