Django模型无法导入Modelform

时间:2018-10-06 18:50:23

标签: django-models

在views.py中是:从django.forms导入Modelform。我仍然收到Importerror。我读了另一篇文章。我究竟做错了什么?以及如何解决?

models.py:

from django.db import models
from datetime import datetime
from django.forms import Modelform
from django.utils import timezone
from django.contrib.auth.models import User
from mytool.forms import Modelform

class Search(models.Model):
    search = models.CharField(max_length=250)
    subject = models.CharField(max_length=150)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

forms.py:

from django import forms
from django.forms import Modelform
from mytool.models import Search

class SearchForm(model.Modelform):
        search = forms.CharField(label ='search', max_length=250, required=True)
        subject = forms.CharField(label ='subject', max_length=150, required=False)
        user = forms.ForeignKey(User, on_delete=forms.CASCADE)

        class Meta:
                model = Search
                fields = ('search', 'subject', 'user',)

0 个答案:

没有答案