我在模型中有一个表单,该表单的字段名为 employee_number ,该表单与另一个名为 Salesman 的模型相关联,该模型包含所有具有雇员姓名的数据,数字,部门等。当前,它仅在输入的员工编号是业务员的情况下才允许提交表格。我正在尝试对它进行过滤,以便只有属于“ MM”和“ OM”团队且employee_status为“ A”的员工才是唯一可以提交的员工。
forms.py
class WarehouseForm(AppsModelForm):
class Meta:
model = EmployeeWorkAreaLog
widgets = {
'employee_number': ForeignKeyRawIdWidget(EmployeeWorkAreaLog._meta.get_field('employee_number').remote_field, site, attrs={'id':'employee_number_field'}),
}
fields = ('employee_number', 'work_area', 'station_number')
models.py
class EmployeeWorkAreaLog(TimeStampedModel, SoftDeleteModel, models.Model):
employee_name = models.CharField(max_length=25)
employee_number = models.ForeignKey(Salesman, on_delete=models.SET_NULL, help_text="Employee #", null=True, blank=False)
work_area = models.ForeignKey(WorkArea, on_delete=models.SET_NULL, null=True, blank=False)
station_number = models.ForeignKey(StationNumber, on_delete=models.SET_NULL, null=True)
def __str__(self):
return self.employee_number
alldata / models.py
class Salesman(models.Model):
id = models.IntegerField(db_column='number', primary_key=True)
team = models.CharField(max_length=2)
employee_status = models.CharField(max_length=1, blank=True)