Error datefiled input when add new record

I have next problem.

I have models: Period and CompletedWork

class Period(models.Model):
    date = models.DateField()

    def __repr__(self):

class CompletedWork(models.Model):
    period = models.ForeignKey(directory.Period,
                               on_delete=models.SET('deleted date'),
    worker = models.ForeignKey(
        on_delete=models.SET('deleted worker'),
        related_name='worker_do', default=settings.AUTH_USER_MODEL
    work_done = models.ForeignKey(directory.WorksType, on_delete=models.SET('deleted works type'))
    work_scope = models.FloatField(blank=True, null=True)
    work_notes = models.CharField(_("Comments"), max_length=70, blank=True, null=True, )
    record_author = models.ForeignKey(
        on_delete=models.SET('deleted user'),
        related_name='record_author', auto_created=True,
    record_date = models.DateTimeField(auto_now=True)
    checked_by_head = models.BooleanField(default=False)
    active = models.BooleanField(default=True)

    def __repr__(self):
        return f'{self.period}, {self.worker}, {self.work_done}'

    def __str__(self):
        return self.__repr__()

    def is_active(self):
            return True
        return False

    def __str__(self):
        return str(self.__repr__())

In the forms I make a widget for Date input:

class CompletedWorkForm(forms.ModelForm):
    class Meta:
        model = CompletedWork

        fields = (
        widgets = {
             'period': DatePickerInput(),
         } looks like this:

class DatePickerInput(forms.DateInput):
    input_type = 'date'

my view:

class CreateCompletedWorkView(LoginRequiredMixin, SuccessMessageMixin, CreateView):
model = CompletedWork
form_class = CompletedWorkForm
template_name = 'completed_work_add.html'
success_url = reverse_lazy('completed_work_list')
success_message = f'Record successfully added'

def get_form_kwargs(self):
    kwargs = super(CreateCompletedWorkView, self).get_form_kwargs()
    kwargs['user'] = self.request.user
    return kwargs

def form_valid(self, form):
    form.instance.record_author = self.request.user
    return super().form_valid(form)

And now I have a problem creating a new record: "Select a valid choice. That choice is not one of the available choices." enter image description here enter image description here

Please tell me how can I fixed. I understand, that maybe problem with the format that I get after POST

Back to Top