hello community,
i have the following database:
class Projects(models.Model):
project = models.CharField(max_length = 999)
domain = models.CharField(max_length = 999)
class KeywordMonitoring(models.Model):
project = models.ForeignKey(to="Projects", on_delete=models.CASCADE)
keyword = models.CharField(max_length = 999)
keywordTag = models.CharField(max_length = 999)
and here is my view:
if request.method == "POST":
_Project = request.POST["project"]
_Project_ID = 0
_Keywords = request.POST["keywords"]
_KeywordTag = request.POST["keywordTag"]
for enter in Projects.objects.all():
if enter.project == _Project:
_Project_ID = enter.id
keywordSet = _Keywords.split(",")
for keyword in keywordSet:
newKeyword = keyword.strip()
KeywordMonitoringModel = KeywordMonitoring(keyword=newKeyword, keywordTag=_KeywordTag, project=_Project_ID)
KeywordMonitoringModel.save()
I get the following error:
ValueError: Cannot assign “1”: “KeywordMonitoring.project” must be a “Projects” instance.
I’ve already browsed the documentation - but unfortunately I don’t know exactly what to look for
The “” Projects “instance” is the ID - or am I wrong?
Thank you in advance