Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.forms.models import model_to_dict
- class Appointments(models.Model):
- polyclinic = models.ForeignKey(Polyclinic,null=True, on_delete=models.SET_NULL)
- service = models.ForeignKey(Services, verbose_name='Услуга',null=True, blank=True, on_delete=models.SET_NULL)
- doctor = models.ForeignKey(Doctor, verbose_name='Доктор',null=True, on_delete=models.CASCADE)
- room_number = models.CharField('Номер кабинета', max_length=30,blank=True, null=True)
- appointment_date = models.DateField('Дата приёма')
- appointment_time = models.TimeField('Время приёма')
- pacient = models.ForeignKey(Patient, verbose_name='Пациент', on_delete=models.SET_NULL, blank=True, null=True)
- status = models.BooleanField('Cостоялся ли прием или нет', default=False)
- def __str__(self) -> str:
- return str(self.doctor) + ' ( ' + str(self.appointment_date) + '-' + str(self.appointment_time) + ' ) ' + str(self.service)
- class Meta:
- verbose_name = 'Расписания приема'
- verbose_name_plural = 'Расписания приемов'
- db_table = 'appointments'
- def to_json(self):
- return model_to_dict(self)
- from .models import Appointments
- def get_info_ticket(request):
- list_json = []
- datas = json.loads(request.GET.get('data', ''))
- for data in datas:
- ticket = Appointments.objects.get(id = data['token_id']).to_json()
- ticket['appointment_date'] = datetime.strftime(ticket['appointment_date'], '%Y-%m-%d')
- ticket['appointment_time'] = str(ticket['appointment_time'])
- ticket['doctor'] = Doctor.objects.get(id = data['doctor_id']).get_full_name()
- ticket['doctor_id'] = data['doctor_id']
- list_json.append(ticket)
- return JsonResponse(json.dumps(list_json), safe=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement