Advertisement
Mochinov

Untitled

Aug 20th, 2021
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1.  
  2. from django.forms.models import model_to_dict
  3.  
  4.  
  5.  
  6. class Appointments(models.Model):
  7.     polyclinic = models.ForeignKey(Polyclinic,null=True, on_delete=models.SET_NULL)
  8.     service = models.ForeignKey(Services, verbose_name='Услуга',null=True, blank=True, on_delete=models.SET_NULL)
  9.     doctor = models.ForeignKey(Doctor, verbose_name='Доктор',null=True, on_delete=models.CASCADE)
  10.     room_number = models.CharField('Номер кабинета', max_length=30,blank=True, null=True)
  11.     appointment_date = models.DateField('Дата приёма')
  12.     appointment_time = models.TimeField('Время приёма')
  13.     pacient = models.ForeignKey(Patient, verbose_name='Пациент', on_delete=models.SET_NULL, blank=True, null=True)
  14.     status = models.BooleanField('Cостоялся ли прием или нет', default=False)
  15.  
  16.     def __str__(self) -> str:
  17.         return str(self.doctor) + ' ( ' + str(self.appointment_date) + '-' + str(self.appointment_time) + ' ) ' + str(self.service)
  18.  
  19.     class Meta:
  20.         verbose_name = 'Расписания приема'
  21.         verbose_name_plural = 'Расписания приемов'
  22.         db_table = 'appointments'
  23.    
  24.     def to_json(self):
  25.         return model_to_dict(self)
  26.  
  27.  
  28.  
  29.  
  30. from .models import Appointments
  31. def get_info_ticket(request):
  32.     list_json = []
  33.     datas = json.loads(request.GET.get('data', ''))
  34.     for data in datas:
  35.         ticket = Appointments.objects.get(id = data['token_id']).to_json()
  36.         ticket['appointment_date'] = datetime.strftime(ticket['appointment_date'], '%Y-%m-%d')
  37.         ticket['appointment_time'] = str(ticket['appointment_time'])
  38.         ticket['doctor'] = Doctor.objects.get(id = data['doctor_id']).get_full_name()
  39.         ticket['doctor_id'] = data['doctor_id']
  40.         list_json.append(ticket)
  41.     return JsonResponse(json.dumps(list_json), safe=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement