是否可以在序列化程序上添加自定义字段验证,这些验证仅根据所述条件在视图中显示特定字段。例如,从下面的模型中有一个访问类,用于考虑患者就诊。根据以下以下状态,人们只会查看某些特定字段,例如假设患者到达,一个人应该只看到visit_start_date
,status_time
将被记录等。
STATUSES=('
('ARRIVED','Arrived'),
('CHECKED_IN','Checked In'),
('IN_ROOM','In Room'),
('CANCELLED','Cancelled'),
('COMPLETE','Complete')
)
class Visit(models.Model):
patient = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name='rel_visits')
discharge_notes = models.TextField(
default=None,
blank=True,
null=True)
discharged = models.NullBooleanField(default=False, null=True, blank=True)
admitted = models.NullBooleanField(default=False, null=True, blank=True)
current = models.NullBooleanField(default=False, null=True, blank=True)
status_time = models.DateTimeField(auto_now_add=True)
status = models.ChoiceField(max_length=20,choices=STATUSES)
visit_start_time = models.DateTimeField(blank=True)
visit_duration = models.IntegerField(blank=True)
session_start_time = models.DateTimeField(blank=True)
session_end_time = models.DateTimeField(blank=True)
check_in = models.BooleanField(default=False)
check_out = models.BooleanField(default=False)
答案 0 :(得分:0)
在您的访问模型中,患者是auth_user_model(Django用户),因此您可以在患者中添加权限(auth_user_model),
1)create custom permission of auth user then
2)create a group called patient, add custom permission on this group.
然后根据权限在views.py
中写一个查询。