Django SubForm没有在Django子视图中出现扭曲

时间:2018-12-10 17:07:09

标签: python django inheritance django-forms django-views

我正在尝试使子窗体在子视图中工作,但是无法使其工作。这主要是继承问题,我尝试了标准的Python方式,但仍然遇到这个问题。错误在底部。

Link代表我要继承的BasketLineForm。

我继承的表单:

from oscar.apps.basket.forms import BasketLineForm as CoreBasketLineForm

class AddBattery(CoreBasketLineForm):
    class Meta(CoreBasketForm.Meta):
          model=Battery
          fields = ('battery_manufacturer', 'battery_capacity', 'battery_warranty')

Link for我从以下网站继承的BasketView:

我继承的视图:

from oscar.apps.basket.views import BasketView as CoreBasketView

class BasketView(CoreBasketView):

    def get_formset_kwargs(self):
        kwargs = super(BasketView, self).get_formset_kwargs()
        kwargs['strategy'] = self.request.strategy
        kwargs['battery']=self.request.modify
        return kwargs


    def get_queryset(self):
        return self.request.basket.all_lines()
    def get_battery_form(self):
        return AddBattery()
    def get_battery_objects(self):
        return Battery.objects.all()

    def get_context_data(self, **kwargs):
        context = super(BasketView, self).get_context_data(**kwargs)
        context['battery_form'] = AddBattery(self.request.POST)
        context['battery_data'] = self.get_battery_objects()
        return context

    def get_success_url(self):
        return safe_referrer(self.request, 'basket:summary')

错误:

Request Method: | GET
-- | --
http://localhost:8000/en/shop/basket/
1.11.15
TypeError
__init__() missing 1 required positional argument: 'strategy'
/home/shazia/oscar/getyoursolar/apps/oscar/basket/views.py in get_context_data, line 69
/home/shazia/oscar/bin/python
3.6.7
['/home/shazia/oscar/getyoursolar',  '/home/shazia/oscar/lib/python36.zip',  '/home/shazia/oscar/lib/python3.6',  '/home/shazia/oscar/lib/python3.6/lib-dynload',  '/usr/lib/python3.6',  '/home/shazia/oscar/lib/python3.6/site-packages']

在第69行上:

def get_context_data(self, **kwargs):
    context = super(BasketView, self).get_context_data(**kwargs)
    context['battery_form'] = AddBattery() #this is line 69
    context['battery_data'] = self.get_battery_objects()
    print(context)
    return context

0 个答案:

没有答案