我在模型中创建了一个人类类,进行了迁移,并出现了错误
没有这样的列
GIT:https://github.com/YouDontDie/tododjango1
class Human(models.Model):
name = models.CharField(max_length=50, verbose_name="Имя")
surname = models.CharField(max_length=50, verbose_name="Фамилия")
birth = models.DateField(auto_now_add=False, auto_now=False)
salary = models.IntegerField()
class TodoList(models.Model): #Todolist able name that inherits models.Model
title = models.CharField(max_length=250) # a varchar
content = models.TextField(blank=True) # a text field
human = models.ForeignKey(Human, default="general", on_delete=models.CASCADE,)
created = models.DateField(default=timezone.now().strftime("%Y-%m-%d")) # a date
due_date = models.DateField(default=timezone.now().strftime("%Y-%m-%d")) # a date
category = models.ForeignKey(Category, default="general", on_delete=models.CASCADE,) # a foreignkey
可见
def index(request): #the index view
todos = TodoList.objects.all() #quering all todos with the object manager
categories = Category.objects.all() #getting all categories with object manager
humans = Human.objects.all()
if request.method == "POST": #checking if the request method is a POS
if "taskAdd" in request.POST: #checking if there is a request to add a tod
title = request.POST["description"] #title
date = str(request.POST["date"]) #date
category = request.POST["category_select"] #category
human = request.POST["human_select"] #category
content = title + " -- " + date + " " + category + " " + human #content
Todo = TodoList(title=title, content=content, due_date=date, category=Category.objects.get(name=category), human=Human.objects.get(name=human))
Todo.save() #saving the tod
return redirect("/") #reloading the page
if "taskDelete" in request.POST: #checking if there is a request to delete a tod
checkedlist = request.POST["checkedbox"] #checked todos to be deleted
for todo_id in checkedlist:
todo = TodoList.objects.get(id=int(todo_id)) #getting tod
todo.delete() #deleting tod
return render(request, "index.html", {"todos": todos, "categories": categories, "humans": humans})