0
我有添加自定義參數到模型的麻煩(在這種情況下,來自request.user的當前用戶) 我曾經這樣做在以前的項目,我不能管理讓它在Django 1.10.4的新項目上工作。將自定義參數添加到django模型
我得到這個錯誤:
TypeError at /realestateprogram/edition_appartement/19/
__init__() got an unexpected keyword argument 'user'
這是我的看法:
apartment = get_object_or_404(Apartment, pk=apartment_id)
if request.method == 'POST':
form = ApartmentForm(request.POST, request.FILES, instance=apartment, user=request.user)
if form.is_valid():
form.save()
return redirect('list_realestateprogram_apartment', realestateprogram_id=apartment.realestateprogram.id)
else:
print form.errors
else:
form = ApartmentForm(instance=apartment, user=request.user)
,這是我的形式:提前
class ApartmentForm(forms.ModelForm):
class Meta:
model = Apartment
exclude = ('realestateprogram',)
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user')
super(ApartmentForm, self).__init__(*args, **kwargs)
感謝,如果你能幫助我
感謝您的回答。當我使用關鍵字args傳遞所有值時,它不起作用:/ – user2323122