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
# 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)
# 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
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WYoYA1nrT7Ne%3DvT1%3Djmk1Omf%3DFo%2BiyuA_ZxsTd152t4EA%40mail.gmail.com.
No comments:
Post a Comment