我在Django中使用我的模型文件获得了以下错误。
"文件" /home/mosmith/Projects/MasteringDjango/mysite/books/models.py",第23行,书中 authors = models.ManyToManyField(作者) NameError:name'作者'未定义"
我已经看到人们遇到的其他问题正在解决这个问题,但是由于没有在通话之前定义模型。
这是我的models.py文件:
from django.db import models
class Arthor(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
def __str__(self):
return self.first_name
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
答案 0 :(得分:0)
<input type="text" name="TextInput1" id="TextInput1" placeholder="place holder" value="" required>
<input type="url" name="urlInput1" id="urlInput1" value="" required>
<input type="number" name="numberInput1" id="numberInput1" value="" required>
<input type="submit" onClick="return validate()" />
<script>
function validate(){
var text1 = document.getElementById('TextInput1').value;
var text2 = document.getElementById('urlInput1').value;
var text3 = document.getElementById('numberInput1').value;
var cnt = 0;
if (text1.length > 0 || text2.length > 0 || text3.length > 0){
alert("working");
return true;
}
alert("please enter something");
return false;
}
</script>
更改为AUTHOR,而不是ARTHOR。