Объект 'set' не является отображением (Ошибка при попытке добавить список вариантов).
Обычно, когда я удаляю из html шаблона {{ createnewauctionhere.category}} все работает, но я хотел бы вывести список, из которого можно выбрать категорию в любом случае. Это часть курса CS50. Не мог бы кто-нибудь объяснить мне, что я делаю не так и где я допускаю ошибку?
models.py
class Category(models.Model):
choicecategory = (
('1','Food'),
('2','Toys'),
('3','Fashion'),
('4','Electronics'),
('5','Home')
)
category = models.CharField(max_length=300, choices=choicecategory)
def __str__(self):
return self.category
class Auctionmodel(models.Model):
title = models.CharField(max_length=300)
content = models.TextField()
price = models.IntegerField()
pic = models.CharField(max_length=300, blank=True)
category = models.ManyToManyField(Category, related_name='Category')
def __str__(self):
return f"Title: {self.title} Content: {self.content} Price: {self.price}"
class Addauctionform(ModelForm):
class Meta:
model = Auctionmodel
fields = '__all__'
widgets = {
"title": TextInput(attrs={'placeholder':"Title Of Auction"}),
"content": Textarea(attrs={'placeholder':"Content Of Auction"}),
"price": NumberInput(attrs={'placeholder':"Price Of Auction"}),
"pic": TextInput(attrs={'placeholder':"Image Of Auction"}),
"category": Select(attrs={'placeholder:"Category Of Auction'})
}
createnewauction.html
<form action="{% url 'createnewauction' %}" method='post'>
{% csrf_token %}
{{ createnewauctionhere.title}} <br>
{{ createnewauctionhere.content}} <br>
{{ createnewauctionhere.price}} <br>
{{ createnewauctionhere.pic }} <br>
{{ createnewauctionhere.category }}
<br>
<input type="submit" value="Create">
</form>