クエリからDjangoフォームを取得しようとしていますが、間違った方法で実行し続けています。いくつかの例を確認しましたが、私は少し違ったやり方をしています。これが私のコードです、
ルフォーム
class ItemForm(ModelForm):
class Meta:
model = Item
exclude = ('deleted')
そしてビューの一部
def index(request):
user = User
try:
last_modified_list = ShoppingList.objects.filter(deleted='0').filter(owner=user).latest('date_modified')
items = Item.objects.filter(shopping_list=last_modified_list).filter(deleted='0')
except ObjectDoesNotExist:
items = Item.objects.filter(deleted='0')
last_used_currency = ExtendedUser.objects.filter(owner=user)
#currency = forms.CharField(initial=last_used_currency.last_currency)
try:
last_used_shoppinglist = ShoppingList.objects.filter(deleted='0').filter(owner=user).latest('date_modified')
except ObjectDoesNotExist:
last_used_shoppinglist = datetime.datetime.now()
item_form = ItemForm (request.POST or None)
item_form.fields["shopping_list"]=last_used_shoppinglist
if item_form.is_valid():
name = item_form.cleaned_data['name']
bought = item_form.cleaned_data['bought']
currency = item_form.cleaned_data['currency']
price = item_form.cleaned_data['price']
date_added = item_form.cleaned_data['date_added']
date_modified = item_form.cleaned_data['date_modified']
date_bought = item_form.cleaned_data['date_bought']
shopping_list = item_form.cleaned_data['shopping_list']
quantity = item_form.cleaned_data['quantity']
deleted = item_form.cleaned_data['deleted']
return render_to_response ('base.html',{'user':user,'items':items,'item_form':item_form}, context_instance=RequestContext(request))
このshopping_list
行は本当に多くのエラーにつながっています。