Hi Folks,
At the time of post request I want to provide only ID and then I want to fetch the details related to that ID from another model and then I want to commit all the deatils inside my ForeignKey table,Please guys tell me How can I do that bu using django rest framewoek?
models.py
class DoctorProfile(models.Model):
# doctor_id = models.IntegerField(primary_key=True)
user = models.OneToOneField(User, on_delete = models.CASCADE,related_name = 'user_profile')
specialities = models.CharField(max_length=100)
start_time = models.TimeField(null = True)
end_time = models.TimeField(null = True)
cost = models.DecimalField(max_digits=6, decimal_places=2)
craeted_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
def __str__(self):
return self.user.username
class Hospital(models.Model):
# hospital_id = models.IntegerField(primary_key=True)
doctor_name = models.ForeignKey(DoctorProfile,on_delete=models.DO_NOTHING)
permanent = models.BooleanField(default = False)
consultant = models.BooleanField(default = False)
craeted_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
I want to add profile details inside Hospital table ForeignKey column, but I want to post opeartion by using this format:
{
"id":2,
" permanent": true,
}
Thanks
Regards,
Soumen