awesto / django-shop

A Django based shop system
http://www.django-shop.org
BSD 3-Clause "New" or "Revised" License
3.18k stars 1.04k forks source link

Error with add CustomizedProductSerializer #765

Closed stilet closed 5 years ago

stilet commented 5 years ago

in doc:

from shop.serializers.bases import ProductSerializer

class CustomizedProductSerializer(ProductSerializer):
        class Meta:
            model = Product
            fields = [all-the-fields-required-for-the-list-view]

and add in url.py

    from django.conf.urls import url
    from shop.views.catalog import ProductListView
    from myshop.serializers import CustomizedProductSerializer

    urlpatterns = [
        url(ProductListView.as_view(
            serializer_class=CustomizedProductSerializer,
        )),
        # other patterns
    ]

I get an error File "/web/garantum/urls.py", line 31, in webapp_1_d116d9535b47 | serializer_class=CustomizedProductSerializer, webapp_1_d116d9535b47 | TypeError: url() missing 1 required positional argument: 'view'

my code in garantum/serializers.py:

class CustomizedProductSerializer(ProductSerializer):
        class Meta:
            model = Programm1c
             fields = ['id', 'product_name', 'product_code', 'product_url',
                  'product_type', 'product_model', 'price']

url.py

urlpatterns = [

     url(ProductListView.as_view(
                serializer_class=CustomizedProductSerializer,
        )),
      url(r'^robots\.txt$', render_robots),
      url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='sitemap'),
       url(r'^shop/', include('shop.urls', namespace='shop')),
       url(r'^', include('myapp.urls')),
    ]

Could not add the product_code field to the product list

jrief commented 5 years ago

Q1:

TypeError: url() missing 1 required positional argument: 'view'

which version of Django are you using?


Q2:

    url(ProductListView.as_view(
        serializer_class=CustomizedProductSerializer,
    )),
    ...

are there any special reasons, you want to hard code the Catalog's List view into your routes, I usually do it through my CMS pages.

stilet commented 5 years ago

Q1:

TypeError: url() missing 1 required positional argument: 'view'

which version of Django are you using?

Q2:

    url(ProductListView.as_view(
        serializer_class=CustomizedProductSerializer,
    )),
    ...

are there any special reasons, you want to hard code the Catalog's List view into your routes, I usually do it through my CMS pages.

Django version: 1.11.20 from https://github.com/awesto/cookiecutter-django-shop There's no reason to do it that way. I need to display the article field in Catalog List and I do the documentation. Sorry for my English )

jrief commented 5 years ago

can I close this?