gpt4 book ai didi

python - Django拆分单词并存储在数据库表中

转载 作者:行者123 更新时间:2023-11-30 23:35:26 28 4
gpt4 key购买 nike

我有一个名为 keykills 的模型。在这个表中,我想用逗号分割关键技能并将其一一存储。示例

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)

这里我想用逗号(,)分割keyskills,它从用户输入中获取并将其一一存储在EMPLOYERKEYSKILLS表中

最佳答案

for skill in keyskills.split(','):
employerkeyskills.objects.create(emp=..., job=..., keyskills=skill)

关于python - Django拆分单词并存储在数据库表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17290472/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com