Найти - Пользователи
Полная версия: Не сохраняется картинка через django-form
Начало » Django » Не сохраняется картинка через django-form
1 2 3 4
wadadaaa
class Product(models.Model):
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    image = models.ImageField(verbose_name=u'Image', upload_to="product_pic", blank=True)
    catalog = models.ForeignKey(Catalog)
    subcatalog = models.ManyToManyField(Subcatalog)
    description = models.TextField(blank=True, help_text="Describe product")
    price = models.DecimalField(max_digits=15, decimal_places=2)
    sale_price = models.DecimalField(max_digits=15, decimal_places=2)
    is_active = models.BooleanField(default=True)
    is_featured = models.BooleanField(default=False)
    quantity = models.IntegerField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    shop = models.ForeignKey(Shop)
    
    def __unicode__(self):
        return self.title
PanovSergey
IntegrityError at /addproduct/
products_product.submitter_id may not be NULL
влючаю режим телепатии
blank=True есть
null=True потерялось
Singularity
wadadaaa
а где ForeignKey на пользователя ?

Мне кажется у вас структура бд и модели не совпадают.
wadadaaa
submitter = models.ForeignKey(User, related_name="product vendor")
думаю добавить в модельку
Singularity
PanovSergey
null=True потерялось
мы ж его ставим сами
PanovSergey
Мне кажется у вас структура бд и модели не совпадают.
Похоже на правду.
wadadaaa
class Product(models.Model):
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    image = models.ImageField(verbose_name=u'Image', upload_to="product_pic", blank=True)
    catalog = models.ForeignKey(Catalog)
    subcatalog = models.ManyToManyField(Subcatalog)
    description = models.TextField(blank=True, help_text="Describe product")
    submitter = models.ForeignKey(User, related_name="product vendor")
    price = models.DecimalField(max_digits=15, decimal_places=2)
    sale_price = models.DecimalField(max_digits=15, decimal_places=2)
    is_active = models.BooleanField(default=True)
    is_featured = models.BooleanField(default=False)
    quantity = models.IntegerField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    shop = models.ForeignKey(Shop)
все равно не сохраняет картинку
wadadaaa
PanovSergey
я не очень понимаю про несовпадение бд и модели
Singularity
wadadaaa
submitter = models.ForeignKey(User, related_name="product vendor")
related_name не может иметь пробелы в имени оно содержит имя по которому можно получить связанные обджекты. Например при related_name=“product_vendor” - User.get.first().product_vendor.all() это все модели которые имеють ForeignKey на конкретного юзера
PanovSergey
Да про null=True, это про эту ошибку
IntegrityError at /addproduct/
products_product.submitter_id may not be NULL
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB