Post request in foreign key details by providing id

13 views
Skip to first unread message

Soumen Khatua

unread,
Aug 31, 2019, 3:45:37 PM8/31/19
to django...@googlegroups.com
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

Gabo LaTo

unread,
Sep 2, 2019, 5:47:33 AM9/2/19
to django...@googlegroups.com
Have you already defined a view in django rest framework?


--
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...@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.
Reply all
Reply to author
Forward
0 new messages