Ejemplo n.º 1
0
class ProductImageMainInline(ImageCroppingMixin, TranslationTabularInline):
    """Изображения продукта"""
    extra = 0
    fields = models.ProductImage().collect_fields()
    model = models.ProductImage
    readonly_fields = ('created', 'updated')
    suit_classes = 'suit-tab suit-tab-images'
Ejemplo n.º 2
0
print('Adding product images...')

#get a list of the product image filenames
filenames = []
for fn in os.listdir('catalog/media/products/'):
    name, ext = os.path.splitext(fn)
    if ext.lower() == '.jpg' and name != 'notfound':
        filenames.append(fn)
random.shuffle(filenames)
images = cycle(filenames)

# add 0-4 images to each product
for product in cmod.Product.objects.all():
    for i in range(random.randint(1, 5)):
        pi = cmod.ProductImage()
        pi.filename = next(images)
        pi.product = product
        pi.save()
        if i == 0:
            name, _ = os.path.splitext(pi.filename)
            product.name = ' '.join((s.capitalize() for s in name.split('_')))
            product.description = '<p>This item is an individual product named %s.<p><p>%s</p>' % (
                product.name, LOREM_IPSUM)
            product.save()

# remove the images from the first product
product = cmod.Product.objects.all().first()
for pi in product.images.all():
    pi.delete()
Ejemplo n.º 3
0
 def bind_images(self, myfile, id):
     # bind product images with product
     pi = m.ProductImage()
     pi.filename = myfile.name
     pi.product = m.Product.objects.get(id=id)
     pi.save()
Ejemplo n.º 4
0
        "The coolest instrument around. Everyone can use a little more triangle in their life."
    ]),
):
    bulk_product = cmod.BulkProduct()
    bulk_product.name = data[0]
    bulk_product.category = cmod.Category.objects.get(codename__exact=data[1])
    bulk_product.brand = data[2]
    bulk_product.price = data[3]
    bulk_product.quantity = data[4]
    bulk_product.reorder_point = data[5]
    bulk_product.reorder_quantity = data[6]
    bulk_product.description = data[8][0]
    bulk_product.save()
    sh.add(user, bulk_product)
    for img in data[7]:
        product_image = cmod.ProductImage()
        product_image.product = bulk_product
        product_image.subdir = img[0]
        product_image.alttext = bulk_product.name
        product_image.mimetype = img[1]
        product_image.is_primary = img[2]
        product_image.save()

# add unique products
for data in (
    ('Trumpet', 'brass', 'Galaxy', Decimal('450.00'), '908839', [
        [dir + 'trumpet.jpg', 'jpg', True],
        [dir + 'trumpet_1.jpg', 'jpg', False],
        [dir + 'trumpet_2.jpg', 'jpg', False],
        [dir + 'trumpet_3.jpg', 'jpg', False],
    ], [