2 回答

TA貢獻1847條經(jīng)驗 獲得超11個贊
def __init__(self, user, *args, **kwargs):
super(BranchesMasterForm, self).__init__(*args, **kwargs)
self.fields['CompanyName'].queryset = BranchesMaster.objects.filter(user=user)

TA貢獻1828條經(jīng)驗 獲得超13個贊
你必須在 models.py 中創(chuàng)建兩個類
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 }
之后創(chuàng)建一個名為 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
添加回答
舉報