我有一个带有名称键功能的模型。在此表中,我想用逗号分隔键盘并逐个存储。实施例
userinput for keyskills = "django,python,html"
in database table(employerkeyskills)
id | emp_id | job_id | keyskills
----|----------|----------|------------
1 | 2 | 1 | django
2 | 2 | 1 | python
3 | 2 | 1 | html
models.py
class User(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
username = models.CharField(max_length=100)
password = models.CharField(max_length=100)
class jobs(models.Model):
emp = models.ForeignKey(User, unique=False)
title = models.CharField(max_length=100)
referencecode = models.CharField(max_length=100)
jobsummary = models.TextField()
jobdetails = models.TextField()
class employerkeyskills(models.Model):
emp=models.ForeignKey(User,unique=False)
job=models.ForeignKey(jobs,unique=False)
keyskills=models.CharField(max_length=50)
这里我想用逗号(,)分割键盘,它来自用户输入并将其一个一个地存储在EMPLOYERKEYSKILLS表中
答案 0 :(得分:3)
for skill in keyskills.split(','):
employerkeyskills.objects.create(emp=..., job=..., keyskills=skill)