py如下
class User_(models.Model):
user_name = models.CharField(max_length=50)
user_password = models.CharField(max_length=50)
user_admin = models.BooleanField(False)
class Project_(models.Model):
project_name = models.CharField(max_length=20)
users = models.ManyToManyField(User_)
project_path = models.FilePathField()
现在我尝试在下面使用 many_to_many 字段用户
usr = User_.objects.get(user_name= userName) #it retrieves the correct object
newProject = Project_(project_name=projectName)
newProject.save()
newProject.users.add(usr) #here is the error
newProject.save()
引发的错误是:“无法将关键字“用户”解析到字段中。选择是:id、project_、user_”
我无法修复该错误,有帮助吗?谢谢。