[英]Django Models data storing
it's my first time working with Django models, I need help with my project.这是我第一次使用 Django 模型,我的项目需要帮助。
I have created 1 model with only field experience, job type, salary.我创建了 1 个只有现场经验、工作类型、薪水的模型。
Now I want another model which stores the table fields.现在我想要另一个存储表字段的模型。 Can anybody please help me?
有人可以帮我吗?
you need to create another model and use ForeignKey like below :您需要创建另一个模型并使用如下外键:
class JobType(models.Model):
name = models.CharField(max_length=150)
class Employee(models.Model):
job_type = models.ForeignKey(JobType, on_delete=models.CASCADE)
experience = ...
salary = ...
There are a lot of resources to learning about Django Model.有很多资源可以学习 Django 模型。 Here is one of the official Documentation.
这是官方文档之一。
https://docs.djangoproject.com/en/3.2/topics/db/models/ https://docs.djangoproject.com/en/3.2/topics/db/models/
If you have more specific question, please explain it clearly.如果您有更具体的问题,请解释清楚。
From your question,从你的问题来看,
from django.db import models
class Person(models.Model):
experience = models.CharField(max_length=30)
job_type = models.CharField(max_length=30)
salary = models.IntegerField()
class AnotherTable(models.Model):
data_1 = models.CharField(max_length=30)
data_2 = models.CharField(max_length=30)
data_3 = models.CharField(max_length=30)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.