F
F
From Prog2022-04-05 09:51:10
Python
From Prog, 2022-04-05 09:51:10

AttributeError: module 'django.forms.models' has no attribute 'Model'?

File "/Users/fromprog/Desktop/projects/students_votings_9b640/major_app/models.py", line 6, in
AttributeError: module 'django.forms.models' has no attribute 'Model'.

The code:

from django.db import models
from django.forms import *

class Texts(models.Model):
  author = fields.CharField('Автор', max_length=50, default='######')
  title = fields.CharField('Название', max_length=100)
  topic = fields.CharField('Тема', max_length=100)
  text = fields.TextField('Текст')
  date = fields.DateTimeField('Дата и время публикации')

  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
Dr. Bacon, 2022-04-05
@bacon

from django.forms import *
don't do it anymore, specify only specific imports, in this case you blocked the previous import from models.
Well, right away, models.CharFieldand not fields.CharField, etc. So importing from forms is not needed at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question