S
S
swpavlov2020-05-07 23:45:30
Python
swpavlov, 2020-05-07 23:45:30

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')


code in views.py
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


code in models.py
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

1 answer(s)
S
Stepan Krapivin, 2020-05-07
@swpavlov

class BbForm(ModelForm):
    class Meta:
        model: Bb <- это что за дичь?

write in pythonmodel = Bb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question