• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python productmodel.Product类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shop.models.productmodel.Product的典型用法代码示例。如果您正苦于以下问题:Python Product类的具体用法?Python Product怎么用?Python Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Product类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: ProductTestCase

class ProductTestCase(TestCase):

    def setUp(self):
        self.product = Product()
        self.product.name = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()

    def test_unicode_returns_proper_stuff(self):
        ret = str(self.product)
        self.assertEqual(ret, self.product.name)

    def test_active_filter_returns_only_active_products(self):
        ret1 = len(Product.objects.active())
        # Set self.product to be active
        self.product.active = True
        self.product.save()
        ret2 = len(Product.objects.active())
        self.assertNotEqual(ret1, ret2)
        self.assertEqual(ret1, 0)
        self.assertEqual(ret2, 1)

    def test_get_name_works_properly_by_default(self):
        res = self.product.get_name()
        self.assertEqual(res, self.product.name)
开发者ID:jrutila,项目名称:django-shop,代码行数:25,代码来源:product.py


示例2: ProductTestCase

class ProductTestCase(TestCase):

    def create_fixtures(self):
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
    
    def test_unicode_returns_proper_stuff(self):
        self.create_fixtures()
        ret = self.product.__unicode__()
        self.assertEqual(ret, self.product.name)
        
    def test_active_filter_returns_only_active_products(self):
        self.create_fixtures()
        ret1 = len(Product.objects.active())
        # Set self.product to be active
        self.product.active = True
        self.product.save()
        ret2 = len(Product.objects.active())
        self.assertNotEqual(ret1, ret2)
        self.assertEqual(ret1, 0)
        self.assertEqual(ret2, 1)
开发者ID:MechanisM,项目名称:django-shop,代码行数:26,代码来源:product.py


示例3: CategoryDetailViewTestCase

class CategoryDetailViewTestCase(TestCase):
    def setUp(self):
        self.cat = Category()
        self.cat.name = 'Test Category'
        self.cat.save()
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        self.product.categories.add(self.cat)
    
    def test_01_get_context_works(self):
        #self.create_fixtures()
        view = CategoryDetailView(kwargs={'pk':self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 1)
        
    def test_02_get_context_works_with_list_of_products(self):
        #self.create_fixtures()
        self.product.active = True
        self.product.save()
        view = CategoryDetailView(kwargs={'pk':self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 2)
开发者ID:agalitsyn,项目名称:django-shop-simplecategories,代码行数:29,代码来源:views.py


示例4: ProductListViewTestCase

class ProductListViewTestCase(TestCase):
    def setUp(self):
        self.product1 = Product()
        self.product1.name = 'test1'
        self.product1.slug = 'test1'
        self.product1.short_description = 'test1'
        self.product1.long_description = 'test1'
        self.product1.unit_price = Decimal('1.0')
        self.product1.active = True
        self.product1.save()

        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.slug = 'test2'
        self.product2.short_description = 'test2'
        self.product2.long_description = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.active = False
        self.product2.save()

    def test_get_queryset(self):
        """
        Test that ProductListView.get_queryset() returns
        only active products, filtering inactive ones.
        """
        view = ProductListView()
        active_products = view.get_queryset()
        self.assertEqual(len(active_products), 1)

        for product in active_products:
            self.assertEqual(product.active, True)
开发者ID:sarva,项目名称:django-shop,代码行数:31,代码来源:views.py


示例5: ProductDetailViewTestCase

class ProductDetailViewTestCase(TestCase):
    def create_fixtures(self):
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        
        self.view = ProductDetailView(kwargs={'pk':self.product.id})
    
    def test_01_get_product_returns_correctly(self):
        self.create_fixtures()
        setattr(self.view, 'object', None)
        obj = self.view.get_object()
        inst = isinstance(obj,Product)
        self.assertEqual(inst, True)
        
    def test_02_get_templates_return_expected_values(self):
        self.create_fixtures()
        self.view = ProductDetailView()
        setattr(self.view, 'object', None)
        tmp = self.view.get_template_names()
        self.assertEqual(len(tmp), 1)
开发者ID:MechanisM,项目名称:django-shop,代码行数:25,代码来源:views.py


示例6: CategoriesTestCase

class CategoriesTestCase(TestCase):
    def setUp(self):
        self.category = Category()
        self.category.name = "test_category"
        self.category.save()
        
        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        self.product.categories.add(self.category)
        
    def test_01_category_unicode_returns_name(self):
        #self.create_fixtures()
        ret = self.category.__unicode__()
        self.assertEqual(ret, self.category.name)
        
    def test_02_category_get_products_works(self):
        #self.create_fixtures()
        ret = self.category.get_products()
        self.assertEqual(len(ret),1)
        cat_product = ret[0]
        self.assertEqual(cat_product,self.product)
开发者ID:agalitsyn,项目名称:django-shop-simplecategories,代码行数:25,代码来源:categories.py


示例7: test_product_adds_additional_categories

 def test_product_adds_additional_categories(self):
     p = Product(
         name='Product 4',
         slug=slugify('Product 4'),
         active=True,
         unit_price=Decimal(random.randint(50, 1000)),
         main_category=Category.objects.get(slug='level1-second')
     )
     
     p.save()
     self.assertEqual(p.additional_categories.all()[0].slug, 'level1-second')
开发者ID:armonge,项目名称:django-shop-categories,代码行数:11,代码来源:__init__.py


示例8: create_fixtures

def create_fixtures(options=False):
    product = Product( name='product 1', slug='product-1', active=True,
                       unit_price=43)
    product.save()
    if not options:
        return
    option_group = OptionGroup(name='option group 1', slug='option-group-1')
    option_group.save()
    option_group.products.add(product)

    Option.objects.create(name='option 1', price='42', group=option_group)
    Option.objects.create(name='option 2', price='84', group=option_group)
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:12,代码来源:test_utils.py


示例9: setUp

    def setUp(self):
        self.product = Product()
        self.product.name = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        
        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.save()
        
        self.product3 = Product()
        self.product3.name = 'test3'
        self.product3.unit_price = Decimal('1.0')
        self.product3.save()

        self.order = Order()
        self.order.order_subtotal = Decimal('10')
        self.order.order_total = Decimal('10')
        self.order.shipping_cost = Decimal('0')
        
        self.order.shipping_name = 'toto'
        self.order.shipping_address = 'address'
        self.order.shipping_address2 = 'address2'
        self.order.shipping_city = 'city'
        self.order.shipping_zip_code = 'zip'
        self.order.shipping_state = 'state'
        self.order.shipping_country = 'country'
        
        self.order.billing_name = 'toto'
        self.order.billing_address = 'address'
        self.order.billing_address2 = 'address2'
        self.order.billing_city = 'city'
        self.order.billing_zip_code = 'zip'
        self.order.billing_state = 'state'
        self.order.billing_country = 'country'
        self.order.save()
        
        self.orderitem1 = OrderItem()
        self.orderitem1.order = self.order
        self.orderitem1.product = self.product
        self.orderitem1.quantity = 5 # this will be the most bought
        self.orderitem1.save()
        
        self.orderitem2 = OrderItem()
        self.orderitem2.order = self.order
        self.orderitem2.product = self.product2
        self.orderitem2.quantity = 1 # this will be the second most
        self.orderitem2.save()
开发者ID:ojii,项目名称:django-shop,代码行数:49,代码来源:product.py


示例10: create_fixtures

    def create_fixtures(self):
        cart_modifiers_pool.USE_CACHE = False

        self.user = User.objects.create(username="test", email="[email protected]", first_name="Test", last_name="Toto")

        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()

        self.ogroup = OptionGroup()
        self.ogroup.product = self.product
        self.ogroup.name = "Test group"
        self.ogroup.save()

        self.option = Option()
        self.option.group = self.ogroup
        self.option.name = "Awesome"
        self.option.price = self.AWESOME_OPTION_PRICE
        self.option.save()

        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

        self.cartitem = CartItem()
        self.cartitem.cart = self.cart
        self.cartitem.quantity = 1
        self.cartitem.product = self.product
        self.cartitem.save()
开发者ID:ojii,项目名称:django-shop-simplevariations,代码行数:34,代码来源:product_options.py


示例11: create_fixtures

 def create_fixtures(self):
     
     self.product = Product()
     self.product.name = 'test'
     self.product.short_description = 'test'
     self.product.long_description = 'test'
     self.product.unit_price = Decimal('1.0')
     self.product.save()
开发者ID:MechanisM,项目名称:django-shop,代码行数:8,代码来源:product.py


示例12: setUp

    def setUp(self):
        cart_modifiers_pool.USE_CACHE = False
        self.user = User.objects.create(username="test",
            email="[email protected]")
        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()
        self.inactive_product = Product(name='InactiveProduct', slug='InactiveProduct', active=False)
        self.inactive_product.save()

        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()
开发者ID:Rue89,项目名称:django-shop,代码行数:18,代码来源:cart.py


示例13: setUp

    def setUp(self):
        self.product1 = Product()
        self.product1.name = 'test1'
        self.product1.slug = 'test1'
        self.product1.short_description = 'test1'
        self.product1.long_description = 'test1'
        self.product1.unit_price = Decimal('1.0')
        self.product1.active = True
        self.product1.save()

        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.slug = 'test2'
        self.product2.short_description = 'test2'
        self.product2.long_description = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.active = False
        self.product2.save()
开发者ID:sarva,项目名称:django-shop,代码行数:18,代码来源:views.py


示例14: setUp

    def setUp(self):

        self.product = Product()
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()

        self.view = ProductDetailView(kwargs={'pk': self.product.pk})
开发者ID:albeirochoa,项目名称:django-shop,代码行数:10,代码来源:views.py


示例15: create_fixtures

 def create_fixtures(self):
     
     self.product = Product()
     self.product.name = 'test'
     self.product.short_description = 'test'
     self.product.long_description = 'test'
     self.product.unit_price = Decimal('1.0')
     self.product.save()
     
     self.view = ProductDetailView(kwargs={'pk':self.product.id})
开发者ID:MechanisM,项目名称:django-shop,代码行数:10,代码来源:views.py


示例16: setUp

    def setUp(self):

        self.product = Product()
        self.product.name = "test"
        self.product.short_description = "test"
        self.product.long_description = "test"
        self.product.unit_price = Decimal("1.0")
        self.product.active = True
        self.product.save()

        self.view = ProductDetailView(kwargs={"pk": self.product.pk})
开发者ID:berrym72,项目名称:django-shop,代码行数:11,代码来源:views.py


示例17: setUp

 def setUp(self):
     self.cat = Category()
     self.cat.name = 'Test Category'
     self.cat.save()
     
     self.product = Product()
     self.product.name = 'test'
     self.product.short_description = 'test'
     self.product.long_description = 'test'
     self.product.unit_price = Decimal('1.0')
     self.product.save()
     self.product.categories.add(self.cat)
开发者ID:agalitsyn,项目名称:django-shop-simplecategories,代码行数:12,代码来源:views.py


示例18: create_fixtures

 def create_fixtures(self):
     self.category = Category()
     self.category.name = "test_category"
     self.category.save()
     
     self.product = Product()
     self.product.name = 'test'
     self.product.short_description = 'test'
     self.product.long_description = 'test'
     self.product.unit_price = Decimal('1.0')
     self.product.category = self.category
     self.product.save()
开发者ID:FinalAngel,项目名称:django-shop-simplecategories,代码行数:12,代码来源:categories.py


示例19: setUp

    def setUp(self):
        self.product = Product()
        self.product.name = 'test'
        self.product.slug = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()

        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.slug = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.save()

        self.product3 = Product()
        self.product3.name = 'test3'
        self.product3.slug = 'test3'
        self.product3.unit_price = Decimal('1.0')
        self.product3.save()

        self.order = Order()
        self.order.order_subtotal = Decimal('10')
        self.order.order_total = Decimal('10')
        self.order.shipping_cost = Decimal('0')

        self.order.shipping_address_text = 'shipping address example'
        self.order.billing_address_text = 'billing address example'
        self.order.save()

        self.orderitem1 = OrderItem()
        self.orderitem1.order = self.order
        self.orderitem1.product = self.product
        self.orderitem1.quantity = 5  # this will be the most bought
        self.orderitem1.save()

        self.orderitem2 = OrderItem()
        self.orderitem2.order = self.order
        self.orderitem2.product = self.product2
        self.orderitem2.quantity = 1  # this will be the second most
        self.orderitem2.save()
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:39,代码来源:product.py


示例20: ProductStatisticsTestCase

class ProductStatisticsTestCase(TestCase):

    def setUp(self):
        self.product = Product()
        self.product.name = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
        
        self.product2 = Product()
        self.product2.name = 'test2'
        self.product2.unit_price = Decimal('1.0')
        self.product2.save()
        
        self.product3 = Product()
        self.product3.name = 'test3'
        self.product3.unit_price = Decimal('1.0')
        self.product3.save()

        self.order = Order()
        self.order.order_subtotal = Decimal('10')
        self.order.order_total = Decimal('10')
        self.order.shipping_cost = Decimal('0')
        
        self.order.shipping_name = 'toto'
        self.order.shipping_address = 'address'
        self.order.shipping_address2 = 'address2'
        self.order.shipping_city = 'city'
        self.order.shipping_zip_code = 'zip'
        self.order.shipping_state = 'state'
        self.order.shipping_country = 'country'
        
        self.order.billing_name = 'toto'
        self.order.billing_address = 'address'
        self.order.billing_address2 = 'address2'
        self.order.billing_city = 'city'
        self.order.billing_zip_code = 'zip'
        self.order.billing_state = 'state'
        self.order.billing_country = 'country'
        self.order.save()
        
        self.orderitem1 = OrderItem()
        self.orderitem1.order = self.order
        self.orderitem1.product = self.product
        self.orderitem1.quantity = 5 # this will be the most bought
        self.orderitem1.save()
        
        self.orderitem2 = OrderItem()
        self.orderitem2.order = self.order
        self.orderitem2.product = self.product2
        self.orderitem2.quantity = 1 # this will be the second most
        self.orderitem2.save()

    def test_top_selling_works(self):
        res = Product.statistics.top_selling_products(10)
        self.assertNotEqual(res, None)
        self.assertEqual(len(res), 2)
        self.assertTrue(self.product3 not in res)
开发者ID:ojii,项目名称:django-shop,代码行数:57,代码来源:product.py



注:本文中的shop.models.productmodel.Product类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cart.get_or_create_cart函数代码示例发布时间:2022-05-27
下一篇:
Python ordermodel.OrderItem类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap