2 回答
TA贡献1847条经验 获得超11个赞
def __init__(self, user, *args, **kwargs):
super(BranchesMasterForm, self).__init__(*args, **kwargs)
self.fields['CompanyName'].queryset = BranchesMaster.objects.filter(user=user)
TA贡献1828条经验 获得超13个赞
你必须在 models.py 中创建两个类
class Sales(models.model):
user = models.ForiegnKey(User , on_delete= models.CASCADE)
{ add more attributes if u want }
class Employee(models.model):
user = models.ForiegnKey(User , on_delete= models.CASCADE)
{ add more attributes if u want }
之后创建一个名为 forms.py 的新文件
class SalesForm(forms.Modelform):
class Meta:
model = Sales
fields = [ 'u can insert the fields which u want to show in ur form ' ]
同样,您为您的员工制作表单类
NOTE:--
u have to import ur model in your form.py module
and do import--- from django.contrib.auth.models import User
in ur models.py file
添加回答
举报