Exemplo n.º 1
0
def add_random_product():
    category = Category.objects.first()
    item = Product()
    item.category = category
    item.name = my_random_string(category.slug)
    item.slug = item.name + '_slug'
    item.price = 1
    item.stock = 2
    item.save()
    return item
Exemplo n.º 2
0
def init_products():
    categories = Category.objects.all()
    for category in categories:
        for number in range(4):
            item = Product()
            item.category = category
            item.name = my_random_string(category.slug)
            item.slug = item.name + '_slug'
            item.price = 1
            item.stock = 2
            item.save()
Exemplo n.º 3
0
Arquivo: views.py Projeto: wooshe/Shop
def main_product(author, category, name, description, material, model, color):
    pr = Product()
    pr.author = author
    pr.category = category
    pr.name = name
    pr.description = description
    pr.material = material
    pr.model = model
    pr.color = color
    pr.price = random.uniform(100, 2000)
    pr.like = random.randint(0, 1000)
    pr.rating = random.uniform(1, 5)
    pr.rating_count = 500
    pr.rating_sum = int(pr.rating * 500)
    pr.save()
Exemplo n.º 4
0
    def handle(self, *args, **options):
        print('shop is working!')
        Category.objects.all().delete()
        for i in all_ctgr:
            c = Category()
            c.name = i
            c.save()
            print(c)

            Product.objects.all().delete()
            for i in phones:
                p = Product()
                p.name = i
                p.category = c
                p.save()
                '''Product.objects.all().delete()
Exemplo n.º 5
0
      def handle(self, *args, **options):
            print('shop is working!')
            Category.objects.all().delete()
            for i in all_ctgr:
                  c = Category()
                  c.name = i
                  c.save()
                  print(c)

                  Product.objects.all().delete()
                  for i in phones:
                        p = Product()
                        p.name = i
                        p.category = c
                        p.save()
                        p.image.save("test.png",
                        File(open('%s/%s' % (MEDIA_ROOT, "icon128.png"), "rb"))
                        )

                        '''Product.objects.all().delete()
Exemplo n.º 6
0
 def handle(self, *args, **options):
     d = Product.objects.all()
     d.delete()
     for c in ShopProduct.objects.using('old').all():
         category = Category.objects.filter(pk=c.category_id).first()
         prod = Product.objects.filter(category=category,
                                       slug=c.slug).first()
         if not prod:
             prod = Product(pk=c.pk)
         prod.name = c.name
         prod.category = category
         prod.slug = c.slug
         prod.title = c.title
         prod.description = c.metadesc
         prod.keywords = c.metakey
         prod.price = c.price
         prod.image = c.image
         prod.description = c.description
         prod.full_text = c.full_text
         prod.save()
         print(prod.id)
Exemplo n.º 7
0
        6, 'Electronic', 'Samsung S9', 'Samsung_S9',
        'products/2018/04/19/S9.jpg', 'Samsung Galaxy S9', 1099, 150, 0
    ],
]
server = Server()

for pic in pic:
    try:
        p = Product.objects.get(pid=pic[0])
    except:
        p = Product()
        p.pid = pic[0]
        category = pic[1]
        try:
            c = Category.objects.get(name=category)
        except:
            c = Category.objects.create(name=category, slug=category)
        p.category = c
        p.name = pic[2]
        p.slug = pic[3]
        p.image = pic[4]
        p.description = pic[5]
        p.price = pic[6]
        p.stock = pic[7]
        p.whnum = pic[8]
        p.save()
        print("fin")
    else:
        continue
server.close()