I have been asked to perform a simple task where I can do the following
- User can register and login as a doctor or patient
- Doctor has many clinics.
- clinic include (name, price, date, start_time, end_time)
- Patients can reserve doctor clinics
- Display doctors and patients reservations
Use Python, django, django rest framework and relational database to complete the task.
I participate in a big project for creating an app for doctor clinics where I'm responsible for creating the previous tasks.
class User(AbstractUser): ... # fields objects = MedicalUserManager()
class MedicalUserManager(models.UserManager): def create_user(self, username, email=None, password=None, **extra_fields): # pop all fields you want to use for `Doctor` or `Patient` from `extra_fields` doctor_pin = extra_fields.pop('doctor_pin', None) pid = extra_fields.pop('pid', None) user = super().create_user(username, email, password, **extra_fields) if doctor_pin: doctor = Doctor.objects.create(user=user, upin=doctor_pin) user.is_doctor = True # not needed if `is_doctor` is in `extra_fields` because it would have been saved when creating the `User` user.save() elif pid: patient = Patient.objects.create(user=user, pid=pid) user.is_patient = True user.save() return user or the following:
class User(AbstractUser): is_doctor = models.BooleanField(default=False) is_patient = models.BooleanField(default=False) class Patient(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) user.is_patient = True pid = models.AutoField(unique=True, primary_key=True) #patient identification class Doctor(models.Model): upin = models.AutoField(primary_key=True) #unique physician identification number user = models.OneToOneField(User, on_delete=models.CASCADE) user.is_doctor = True expertise = models.CharField(max_length=20) days_available = models.DateTimeField(null=True) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: if instance.is_patient: Patient.objects.create(user=instance) elif instance.is_doctor: Doctor.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): if instance.is_patient: instance.patient.save() elif instance.is_doctor: instance.doctor.save() I would like to 1) check the following classes 2) explaining endpoints in views.py & restful 3) How to do register & login for both https://stackoverflow.com/questions/67051839/how-to-do-a-quick-user-registration-crud-on-simple-app April 12, 2021 at 10:07AM
没有评论:
发表评论