How to get parameter in _clean method of form?

Maybe I'm fundamentally something wrong implement.
Task: you Have a tool. Is it moving between counterparties. It is necessary to check that the date of moving not earlier than the date of the last transfer.

class Tool(models.Model):
 name = models.CharField(max_length=128, blank=False)
 code_number = models.CharField(max_length=8, blank=True, null=True, unique=True)
 buy_date = models.DateField(blank=True, null=True)
 comment = models.TextField(blank=True)

class ToolMove(models.Model):
 tool = models.ForeignKey(Tool, on_delete=models.CASCADE)
 date = models.DateField(blank=True)
 to_supplier = models.ForeignKey(Supplier, related_name='to_supplier', on_delete=models.PROTECT)
 comment = models.TextField(blank=True)


Add move is performed from the card of the instrument (DetailView). The query parameter tool_pk.
path('toolmove/<int:tool_pk>/create/', ToolMoveCreateView.as_view(), name='toolmove_create_url'),

Because of the fields is not taken from the form, create a move in the following way (here it is not sure that the approach is correct, smirenie for the curve code and description of how to do better is welcomed :):
def post(self, request, tool_pk):
 tool = get_object_or_404(Tool, pk=tool_pk)
 bound_form = self.form_name(request.POST)

 if bound_form.is_valid():
 toolmove = ToolMove()
 toolmove.tool = tool
 toolmove.date = bound_form.cleaned_data['date']
 toolmove.to_supplier = bound_form.cleaned_data['to_supplier']
 toolmove.comment = bound_form.cleaned_data['comment']
toolmove.save()
 if self.redirect_url:
 return redirect(self.redirect_url)
else:
 return redirect(tool)
 action_url = reverse(self.action_url, kwargs={'tool_pk': tool_pk})
 record_name = self.record_name
 context = {
 'form': bound_form, 
 'action_url': action_url,
 'record_name': record_name,
 'tool': tool
}
 return render(request, self.template, context=context)

That is, because not all attributes are entered in the form, do so. Then you probably had a tool to put in a hidden field and get all out of shape, but it happens that some of the attributes are obtained from a database or by calculations. This approach (when not using the form.save () and create object and some attributes are taken from the form part of the method of computing and from the database and store) has the right to life or it is necessary somehow in another way?

Create a method to check the date:
def clean_date(self):
 new_date = self.cleaned_data['date']
 last_date = ToolMove.objects.filter(tool=???).last()
 if last_date.date > new_date:
 raise ValidationError('movement date cannot be earlier than the last move')

 return new_date

And then to get the latest date for the tool, I need the pk of the tool, which is passed to GET.
April 19th 20 at 12:08
1 answer
April 19th 20 at 12:10
As a variant still to cram in tool_pk bound_form before calling is_valid(), but the option seems awful.

Find more questions by tags Django