在Models.py文件中(我有此代码库)
writer.writerow(the_printed_values)
在Admin.py文件中(我有这个)
class Person(models.Model):
sex_choices = (
('Male', 'Male'),
('Female', 'Female')
)
martial_choices = (
('Single', 'Single'),
('Married', 'Married'),
('Divorce', 'Divorce'),
('Widowed', 'Widowed')
)
name = models.CharField(max_length=200)
sex = models.CharField(choices=sex_choices, max_length=50)
martial_status = models.CharField(choices=martial_choices, max_length=50)
age = models.IntegerField()
def __str__(self):
return self.name
class DetailsOfEducationQualification(models.Model):
type_choice = (
("Government", "Government"),
("Private", "Private"),
("Anganwadi Center", "Anganwadi Center"),
)
education_proximity_choice = (
("0-5", '0-5km'),
('5-10', '5-10km'),
('10+', 'Above 10km'),
('Outside the state', 'Outside the state'),
)
person = models.ForeignKey(Person, on_delete=models.CASCADE)
course_class = models.CharField(max_length=50, blank=True)
type_of_education_sector = models.CharField(choices=type_choice, max_length=50, blank=True)
education_facility_proximity = models.CharField(choices=education_proximity_choice, max_length=50, blank=True)
在查询外壳中,由于DetailsOfEducationQualification模型与Person相关,因此我想获取人员“ course_class”:
就像他的查询一样:
from .models import (
Person, DetailsOfEducationQualification
)
class DetailsOfEducationQualificationInline(admin.TabularInline):
model = DetailsOfEducationQualification
extra = 0
class PersonAdmin(admin.ModelAdmin):
fieldsets = [
(
'Personal Information', {
'fields':[
'name', 'sex', 'age', 'martial_status'
]
}
),
]
inlines = [
DetailsOfEducationQualificationInline
]
此代码出错,表示人没有属性... 如何从Person模型访问DetailsOfEducationQualification日期?