S
S
sportik1742020-12-16 19:12:18
Django
sportik174, 2020-12-16 19:12:18

Why is the 'list' object is not callable error coming out?

Good day, the question is this:

I create a Collections model object in the database:

def test(request):
  collection_add = Collections(
      title = 'Тестовый заголовок',
      slug = 'slug-slug',
      price = 255,
      img = 'dkjgklj.png'
    )


  fabrik = Fabriks.objects.get(title='Aparici')
  category = Category.objects.get(title='Керамическая плитка')
  collection_add.fabrik = fabrik
  collection_add.category = category

  collection_add.save()


  return render(request, 'main/main.html')


I get this error:
5fda30fe8d253456637625.png

Collections Model:
class Collections(models.Model):
    title = models.CharField(max_length=255, verbose_name='Название')
    slug = models.SlugField(unique=True)
    img = models.ImageField(verbose_name='Фото')
    price = models.PositiveIntegerField(default=0, verbose_name='Цена от')
    fabrika = models.ForeignKey('Fabriks', verbose_name='Производитель', on_delete=models.CASCADE)
    category = models.ForeignKey('Category', verbose_name='Категория', on_delete=models.CASCADE)

    def __str__(self):
        return self.title
        
    class Meta:
        verbose_name = 'Коллекция'
        verbose_name_plural = 'Коллекции'


Fabric Model:
class Fabriks(models.Model):
    country = models.ForeignKey('Country', verbose_name='Страна', on_delete=models.CASCADE)
    title = models.CharField(max_length=255, verbose_name='Название')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'Производитель'
        verbose_name_plural = 'Производители'


Model Category:
class Category(models.Model):
    title = models.CharField(max_length=255, verbose_name='Название')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'Категория'
        verbose_name_plural = 'Категории'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2020-12-16
@sportik174

I can be wrong, but Python perceives this as Collections
Include debug, breakpoint on model creation and try

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question