无法将关键字“有效”解析为字段。选择是

时间:2019-11-28 02:39:31

标签: python django woocommerce

我正在关注在线教程。但是现在让我发疯。我正在尝试更新视图。但老实说,几天后我找不到问题。我一直在跟踪,但我可以得到它。我将无法解析关键字“有效”输入字段。选项包括:激活,购物车,cart_id,id,产品,product_id,数量消息

点击按钮获取产品详细信息并创建新产品或将产品添加到购物车后,消息将显示

>     lookups, parts, reffed_expression = self.solve_lookup_type(arg)   File
> "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1049, in solve_lookup_type

>     _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())   File
> "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1419, in names_to_path
>     raise FieldError("Cannot resolve keyword '%s' into field. " django.core.exceptions.FieldError: Cannot resolve keyword 'active'
> into field. Choices are: activate, cart, cart_id, id, product,
> product_id, quantity [28/Nov/2019 02:18:14] "GET /cart HTTP/1.1" 500
> 106045 [28/Nov/2019 02:18:26] "GET /cart/add/5 HTTP/1.1" 302 0
> Internal Server Error: /cart Traceback (most recent call last):   File
> "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\core\handlers\exception.py",
> line 34, in inner
>     response = get_response(request)   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\core\handlers\base.py",
> line 115, in _get_response
>     response = self.process_exception_by_middleware(e, request)   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\core\handlers\base.py",
> line 113, in _get_response
>     response = wrapped_callback(request, *callback_args, **callback_kwargs)   File "C:\Users\k-her\OneDrive\Escritorio\New\store\views.py", line 51, in
> cart_detail       
>     cart_items = CartItem.objects.filter(cart=cart, active=True)   File
> "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\manager.py",
> line 82, in manager_method
>     return getattr(self.get_queryset(), name)(*args, **kwargs)   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\query.py",
> line 892, in filter
>     return self._filter_or_exclude(False, *args, **kwargs)   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\query.py",
> line 910, in _filter_or_exclude
>     clone.query.add_q(Q(*args, **kwargs))   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1290, in add_q
>     clause, _ = self._add_q(q_object, self.used_aliases)   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1315, in _add_q
>     child_clause, needed_inner = self.build_filter(   File "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1190, in build_filter
>     lookups, parts, reffed_expression = self.solve_lookup_type(arg)   File
> "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1049, in solve_lookup_type
>     _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())   File

> "C:\Users\k-her\OneDrive\Escritorio\New\env\lib\site-packages\django\db\models\sql\query.py",
> line 1419, in names_to_path

>     raise FieldError("Cannot resolve keyword '%s' into field. " django.core.exceptions.FieldError: Cannot resolve keyword 'active'
> into field. Choices are: activate, cart, cart_id, id, product,

> product_id, quantity [28/Nov/2019 02:18:26] "GET /cart HTTP/1.1" 500
> 105910

我的网址

urlpatterns = [    
     path('', views.home, name='home'),
     path('category/<slug:category_slug>', views.home, name='products_by_category'),
     path('category/<slug:category_slug>/<slug:product_slug>', views.productPage, name='product_detail'),
     path('cart/add/<int:product_id>', views.add_cart, name='add_cart'),
     path('cart', views.cart_detail, name='cart_detail'), ]

观看次数

def cart_detail(request, total=0, counter=0, cart_items =None):

    try:
        cart = Cart.objects.get(cart_id=_cart_id(request))
        cart_items = CartItem.objects.filter(cart=cart, active=True)
        for cart_item in cart_items:
            total += (cart_item.product.price * cart_item.quantity)
            counter += cart_item.quantity
    except ObjectDoesNotExist:

        pass
    return render(request, 'cart.html', dict(cart_items = cart_items, total = total, counter = counter))

班级

class CartItem(models.Model):
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
    quantity = models.IntegerField()
    activate = models.BooleanField(default=True)

    class Meta:
        db_table = 'CartItem'

    def sub_total(self):
        return self.product.price * self.quantity

    def __str__(self):
        return self.product

0 个答案:

没有答案