我正在构建一个应用程序。我正在尝试显示2种不同模型的字段。咨询和咨询。 list_display函数适用于咨询服务,但不适用于咨询服务。它仅显示一个字段(开始日期)。在咨询模型中,有一个链接到咨询类型的前键。我想知道这是否引起了问题。我添加了在咨询和咨询之间创建父母与孩子的关系。 预先感谢您的帮助
我尝试使用其他注册方法(通过装饰器,admin.site.register,admin.site.register(Consultation,ConsultationAdmmin))。
Models.py:
from django.contrib.auth.models import User
from django.db import models
import uuid
from datetime import date
from django.urls import reverse # Used to generate URLs by reversing the URL patterns
class ConsultationSerie(models.Model):
"""Model representing a consultation process (define by the relationship between a patient and a doctor) but notr a specific consultation"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text = 'Unique ID for this particular Consultation process' )
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
patient = models.ForeignKey('Patient', on_delete=models.SET_NULL, null=True)
doctor = models.ForeignKey('Doctor', on_delete=models.SET_NULL, null=True)
def __str__(self):
"Number representing the consultation process"
# return str(self.id)
return self.patient.lastname + "&" + self.doctor.lastname
def get_absolute_url(self):
"""Returns the url to access a detail record for this consultation process"""
return reverse('consultation-detail',args=[str(self.id)])
class Consultation(models.Model):
"""Model representing a specific consultation"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular consultation')
# consultationserie = models.ForeignKey(ConsultationSerie, on_delete=models.SET_NULL, null=True)
status = models.CharField(max_length=200)
start_date = models.DateField(null=True, blank=True)
end_date = models.DateField(null=True, blank=True)
CONSULTATION_STATUS = (
('o', 'reserved'),
('c', 'cancelled'),
('a', 'ajourned'),
('d', 'done'),
)
status = models.CharField(
max_length=1,
choices=CONSULTATION_STATUS,
blank=True,
default='o',
help_text='Consultation status',
)
class Meta:
ordering = ['start_date']
def __str__(self):
"""String for representing the Model object."""
# return f'{self.id} ({self.consultationserie.id})'
return str(self.start_date)
@property
def is_passed(self):
if self.end_date and date.today() > self.end_date:
return True
return False
Admin.py:
from django.contrib import admin
from monkyrosite.models import id_adress, Patient, Doctor, PatientInstance, DoctorInstance, ConsultationSerie, Consultation
admin.site.register(id_adress)
admin.site.register(Patient)
admin.site.register(PatientInstance)
admin.site.register(Doctor)
admin.site.register(DoctorInstance)
@admin.register(ConsultationSerie)
class ConsultationSerie(admin.ModelAdmin):
list_display = ('id','doctor','patient')
fieldsets = (
(None,{
'fields':('patient','doctor','id')
}),
)
@admin.register(Consultation)
class Consultation(admin.ModelAdmin):
list_diplay = ('status','start_date','end_date')
fieldsets = (
(None,{
'fields': ('status','start_date','end_date')
}),
)
当我单击Django Admin中的Consultations链接时,预期的结果是在管理窗口中显示的开始日期结束日期和状态。
预先感谢您的帮助。