当前位置: 首页>>代码示例>>Python>>正文


Python Product.create方法代码示例

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


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

示例1: setUp

# 需要导入模块: from products.models import Product [as 别名]
# 或者: from products.models.Product import create [as 别名]
    def setUp(self):        
        """
        Set up for the Acknowledgement Test

        Objects created:
        -User
        -Customer
        -Supplier
        -Address
        -product
        -2 fabrics

        After Creating all the needed objects for the Acknowledgement, 
        test that all the objects have been made.
        """
        super(ShippingResourceTest, self).setUp()
        
        self.ct = ContentType(app_label="shipping")
        self.ct.save()

        #Create the user
        self.username = 'tester'
        self.password = 'pass'
        self.user = User.objects.create_user(self.username, '[email protected]', self.password)
        self.user.save()
        
        p = Permission(content_type=self.ct, codename="change_shipping")
        p.save()
        p2 = Permission(content_type=self.ct, codename="add_shipping")
        p2.save()
        self.user.user_permissions.add(p)
        self.user.user_permissions.add(p2)
        
        self.user.save()

        self.setup_client()

        
        #Create supplier, customer and addrss
        self.customer = Customer(**base_customer)
        self.customer.save()
        self.supplier = Supplier(**base_supplier)
        self.supplier.save()
        self.address = Address(address1="Jiggle", contact=self.customer)
        self.address.save()
        
        #Create project
        self.project = Project.objects.create(codename="Ladawan")
        
        #Create phase
        self.phase = Phase.objects.create(description="Phase 1/6", project=self.project)
        
        #Create a product to add
        self.product = Product.create(self.user, **base_product)
        self.product.save()
        self.fabric = Fabric.create(**base_fabric)
        f_data = base_fabric.copy()
        f_data["pattern"] = "Stripe"
        self.fabric2 = Fabric.create(**f_data)
        
        #Create acknowledgement
        ack_data = base_ack.copy()
        del ack_data['customer']
        del ack_data['items']
        del ack_data['employee']
        self.ack = Acknowledgement(**ack_data)
        self.ack.customer = self.customer
        self.ack.employee = self.user
        self.ack.save()
        
        #Create an item
        item_data = {'id': 1,
                     'quantity': 1,
                     'is_custom_size': True,
                     'width': 1500,
                     "fabric": {"id":1}}
        self.item = AckItem.create(acknowledgement=self.ack, **item_data)
        
        #Create an item
        item_data = {'id': 1,
                     'quantity': 2,
                     'is_custom_size': True,
                     'width': 1500,
                     "fabric": {"id":1}}
        self.item2 = AckItem.create(acknowledgement=self.ack, **item_data)
开发者ID:charliephairoj,项目名称:backend,代码行数:87,代码来源:tests.py


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