Actually my query is different I want to do Get, Post and Update(Crud) operation by using rest framework on that following models. Thanks for your response.
On Sun, 11 Aug 2019, 03:08 mohamed habib, <moe.hab...@gmail.com> wrote: > You can use a signal to ensure that a profile is created for each user. > Make sure all the fields in your Profile model are nullable: > > ``` > class Profile(models.Model): > > GENDER_CHOICES = ( > ('male', 'Male'), > ('female', 'Female') > ) > user = models.ForeignKey(User,on_delete=models.CASCADE,related_name = > 'usermodel') > permanent_address_city = > models.ForeignKey(Address,on_delete=models.CASCADE,related_name = > 'permanent_address_city', null=True, blank=True) > phone_number = models.PositiveIntegerField(, null=True, blank=True) > gender = models.CharField(max_length = 5,choices = GENDER_CHOICES, > null=True, blank=True) > profile_pic = models.ImageField(upload_to='profile_pic',default = > 'default.jpg', null=True, blank=True) > created_at = models.DateField(auto_now_add = True, null=True, blank=True) > updated_at = models.DateField(auto_now = True, null=True, blank=True) > > ``` > > use signal within your models.py to create a blank profile every time a User > object is created: > > > ``` > > from django.db.models.signals import post_save > > from django.dispatch import receiver > @receiver(post_save, sender=settings.AUTH_USER_MODEL)def > create_user_profile(sender, instance, created, **kwargs): > if created: > UserProfile.objects.create(user=instance) > > ``` > > Now you can create an Update profile view to update the user based on the > fields he has placed in the instance using your serialiser. You can have a > separate view to create an address object. The User Profile update view can > take the ID of an address and attach that address to the user. > > > > On Sat, Aug 10, 2019 at 9:55 PM Soumen Khatua <soumenkhatua...@gmail.com> > wrote: > >> Hi Folks, >> My requirement is whenever i create a user in post method that user can >> pass username and password, Address models contain some field and Profile >> models contains some field. If he is authenticated users and want to create >> one prifile he need to pass Address model contains some field and Profile >> models contain some fields information. I'm stuckung in this problem from >> last four days. Please help me with complete code actually I'm not that >> much good in Django rest framework. please help me guys. >> >> These are my models for your reference: >> >> >> models.py: >> --------------- >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> *from django.db import modelsfrom django.contrib.auth.models import User# >> Create your models here.class Address(models.Model): street_no = >> models.CharField(max_length = 65) city = models.CharField(max_length = >> 65) state = models.CharField(max_length = 65) pincode = >> models.CharField(max_length = 65) country = models.CharField(max_length >> = 65) created_at = models.DateField(auto_now_add = True) updated_at = >> models.DateField(auto_now = True) def __str__(self): return >> self.cityclass Profile(models.Model): GENDER_CHOICES = ( ('male', >> 'Male'), ('female', 'Female') ) user = >> models.ForeignKey(User,on_delete=models.CASCADE,related_name = >> 'usermodel') permanent_address_city = >> models.ForeignKey(Address,on_delete=models.CASCADE,related_name = >> 'permanent_address_city') phone_number = models.PositiveIntegerField() >> gender = models.CharField(max_length = 5,choices = GENDER_CHOICES) >> profile_pic = models.ImageField(upload_to='profile_pic',default = >> 'default.jpg') created_at = models.DateField(auto_now_add = True) >> updated_at = models.DateField(auto_now = True)* >> >> >> *Thank you in advance* >> >> -- >> 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+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAPUw6WZCT_fB-bgjWmLTiPDG81V5Vg-BPqeeps_QivtpddrkaQ%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAPUw6WZCT_fB-bgjWmLTiPDG81V5Vg-BPqeeps_QivtpddrkaQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Best regards, > *Mohammed M. Habib, PhD* > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CA%2BpnY8ZpccqyPTpk8ckkqV2QiF%2BLBpGDeNA3hag0F%2Bx6wZq2Dw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CA%2BpnY8ZpccqyPTpk8ckkqV2QiF%2BLBpGDeNA3hag0F%2Bx6wZq2Dw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WbTyi6mT2jchsRKeRtcypcbCL7jA-9ieLrgJY3So2O3Ng%40mail.gmail.com.