Answer the question
In order to leave comments, you need to log in
ValueError: ModelForm has no model class specified?
An error is displayed. For several hours I can not find an error in the code
code in forms.py
class BbForm(ModelForm):
class Meta:
model: Bb
fields = ('title', 'content', 'price', 'published', 'rubric')
class BbCreateView(CreateView):
template_name = 'bboard/create.html'
form_class = BbForm
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['rubrics'] = Rubric.objects.all()
return context
class Bb(models.Model):
title = models.CharField(max_length=50, verbose_name='Товар')
content = models.TextField(null=True, blank=True, verbose_name='Описание')
price = models.FloatField(null=True, blank=True, verbose_name='Цена')
published = models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='Опубликовано')
rubric = models.ForeignKey('Rubric', null=True, on_delete=models.PROTECT, verbose_name='Рубрика')
class Meta:
verbose_name_plural = 'Объявления'
verbose_name = 'Объявление'
ordering = ['-published']
Answer the question
In order to leave comments, you need to log in
class BbForm(ModelForm):
class Meta:
model: Bb <- это что за дичь?
model = Bb
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question