Answer the question
In order to leave comments, you need to log in
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')
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 = 'Коллекции'
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 = 'Производители'
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
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 questionAsk a Question
731 491 924 answers to any question