def __init__(self,*args,**kwargs):
super (AppointmentForm,self ).__init__(*args,**kwargs) # populates the post
#filter appointments based on status
if self.instance.pk:
# the location filter below is a guess. i don't know your models.
locations = Location.objects.filter(status_id=self.instance.status_id)
self.fields['location'].queryset = locations
1 回答
如果您的实例是现有的,而不是内联形式,则可以在模型表单中执行以下操作:
另一种方法是使用Callbacks变得更加棘手......