Raw input being recorded but data is not saving throwing “this field is required” error

For context, I’ve essentially got a form whereby the user fills in job details and can choose who was on the job from an existing list of workers and input their hours, rates, and total wages. I’ve implemented a script so the user can ‘add’ more workers to the form. The main issue is that the data is not saving specifically for the hours and rates field even though the wages field is, so I cannot submit the whole form. Given the JS is client-side it is more likely a django problem, I’ve tested it anyway by getting rid of my script.

Wage Model:




    
class EmployeeWage(models.Model):
    job = models.ForeignKey(Operating_Budget, on_delete=models.CASCADE, null=True, blank=True)
    worker = models.ForeignKey(EmployeeRecord, on_delete=models.CASCADE, null=True, blank=True)
    wages = models.DecimalField(max_digits=10, decimal_places=2)
    hours = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    rates = models.DecimalField(max_digits=10, decimal_places=2,default=0)

This is my Wage form:



class WorkerWagesForm(forms.ModelForm):
    worker = forms.ModelChoiceField(queryset=EmployeeRecord.objects.all(), label="")
    wages = forms.DecimalField(label="", max_digits=10, decimal_places=2)
    hours = forms.DecimalField(label="", max_digits=10, decimal_places=2)
    rates = forms.DecimalField(label="", max_digits=10, decimal_places=2)

    class Meta:
        model = EmployeeWage
        fields = ('worker', 'wages', 'hours', 'rates')

class JobWorkerWageFormSetBase(BaseInlineFormSet):
    def clean(self):
        super().clean()
        for form in self.forms:
            if form.cleaned_data.get('hours') is None:
                form.add_error('hours', 'Hours are required.')
            if form.cleaned_data.get('rates') is None:
                form.add_error('rates', 'Rates are required.')
WorkerWagesFormSet = inlineformset_factory(Operating_Budget, EmployeeWage, formset = JobWorkerWageFormSetBase, fields=('worker', 'wages', 'hours', 'rates'), extra=1, can_delete=True)

And view:

def addrev(request):
    
    
    if request.method == 'POST':
        print(request.POST)
        job_form = Revenue(request.POST)
        formset = WorkerWagesFormSet(request.POST, request.FILES)
        
        print(formset.data)

        if job_form.is_valid() and formset.is_valid():
            print("Job Form cleaned data:", job_form.cleaned_data)
            job = job_form.save()
            job_worker_wages = formset.save(commit=False)
            for job_worker_wage in job_worker_wages:
                job_worker_wage.job = job
                job_worker_wage.save()
                worker = job_worker_wage.worker
                if worker:
                    worker.job_completed += 1
                    worker.save()
                    print (worker)
        
            return redirect('revenue')
        else:
             print(formset.errors)
             print(job_form.errors)
        

    else:
        job_form = Revenue()
        formset = WorkerWagesFormSet()

    return render(request, 'addrev.html', {
        'job_form': job_form,
        'formset': formset,
    })
This is the error message:

[{'hours': ['This field is required.', 'Hours are required.'], 'rates': ['This field is required.', 'Rates are required.']}]

I’ve checked multiple times to see if the field type in the models and forms were different which i couldn’t find any differences. All other inputs were valid.

Any help would be appreciated! Thank you

New contributor

TargetToo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật