I'm trying to override form but am getting multitple value for argument 'instance'
this is my form class
class MarketProductForm(forms.ModelForm):
lists = FarmerRequest.objects.all()
request = forms.ModelChoiceField(queryset=lists)
class Meta:
model = MarketProduct
fields = '__all__'
def __init__(self, instance=None, *args, **kwargs):
super().__init__(instance=instance, *args, **kwargs)
if instance:
requests = MarketProduct.objects.all()
request_list = []
for req in requests:
request_list.append(req.request.id)
# lists = FarmerRequest.objects.filter(~Q(id__in=request_list))
lists = FarmerRequest.objects.all()
self.fields['request'].queryset = lists
else:
requests = MarketProduct.objects.all()
request_list = []
for req in requests:
request_list.append(req.request.id)
lists = FarmerRequest.objects.filter(~Q(id__in=request_list))
self.fields['request'].queryset = lists
inside my admin.py
form = MarketProductForm
question from:
https://stackoverflow.com/questions/65642633/init-got-multiple-values-for-argument-instance 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…