Answer the question
In order to leave comments, you need to log in
How to import from *.xlsx to a model?
There are models
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=200, verbose_name="Категория")
class Meta:
ordering = ["name"]
verbose_name = "Категория"
verbose_name_plural = "Категории"
def __str__(self):
return self.name
'''def get_update_url(self):
return reverse('category_update', args=[str(self.id)])
def get_delete_url(self):
return reverse('category_delete', args=[str(self.id)])'''
def default_vendor_code():
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
class Product(models.Model):
title = models.CharField(max_length=200, verbose_name="Название товара")
category = models.ForeignKey(Category, verbose_name="Категория", on_delete=models.SET_NULL, null=True)
vendor_code = models.CharField(max_length=20, verbose_name="Артикул", default=default_vendor_code)
image = models.ImageField(upload_to="catalog/", verbose_name="Изображение", default="catalog/default.png")
width = models.PositiveIntegerField(verbose_name="Ширина", help_text="Указывать в мм")
height = models.PositiveIntegerField(verbose_name="Высота", help_text="Указывать в мм")
length = models.PositiveIntegerField(verbose_name="Длина", help_text="Указывать в мм")
class Meta:
ordering = ["title"]
verbose_name = "Товар"
verbose_name_plural = "Товары"
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('product-detail', args=[str(self.id)])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question