On Sun, Oct 18, 2020 at 8:15 AM Softtar <softta...@gmail.com> wrote: > Yes Thanks Sir. It's working Now. Thanks again Sir. I have one more > question > > I want to pass condition base parameters in url how i can do that > > path('api/filterapplication/<cnic> || <mobile>', ApplicationLIST1.as_view()), > > > def get(self, request, cnic, mobile): > snippets = Application.objects.filter(cnic=cnic) | > Application.objects.filter(mobile=mobile) > serializer = ApplicationSerializer(snippets, many=True) > return Response(serializer.data) > > > > > > > That syntax in path() is not supported: https://docs.djangoproject.com/en/3.1/ref/urls/#path https://docs.djangoproject.com/en/3.1/topics/http/urls/
One way is having two endpoints, one for cnic and other for mobile, another is using GET parameters (url resource filtering) You can find the rationales in the Internet ("REST API design"), also take a look at the resources listed here: https://www.django-rest-framework.org/topics/rest-hypermedia-hateoas/ > On Sun, Oct 18, 2020 at 6:12 PM Jakob Damgaard Møller <jako...@gmail.com> > wrote: > >> Add obj. In front of all four chases. >> >> søn. 18. okt. 2020 kl. 15.07 skrev Softtar <softta...@gmail.com>: >> >>> class ListAppsSerializer(serializers.ModelSerializer): >>> full_address = serializers.SerializerMethodField() >>> >>> class Meta: >>> model = Application >>> fields = ('id', 'full_address', 'status') >>> >>> def get_full_address(self, obj): >>> return f"{address1} {address2} {address3} {addres4}" >>> >>> it's saying address1 address2 address3 and address4 is not define >>> >>> >>> On Sun, Oct 18, 2020 at 5:17 PM Jakob Damgaard Møller <jako...@gmail.com> >>> wrote: >>> >>>> Try this one: >>>> >>>> class YourSerializer(serializers.ModelSerializer): >>>> full_address = serializers.SerializerMethodField() >>>> >>>> class Meta: >>>> model = Application >>>> fields = ('id', 'full_address','status') >>>> >>>> def get_full_address(self, obj): >>>> return f"{address1} {address2} {address3} {addres4}" >>>> >>>> On Sun, Oct 18, 2020 at 1:15 PM Softtar <softta...@gmail.com> wrote: >>>> >>>>> class Meta: >>>>> model = Application >>>>> fields = ('id', 'address1', 'address2', 'address3', 'status') >>>>> >>>>> def to_representation(self, instance): >>>>> response_dict = dict() >>>>> response_dict['id'] = instance.id >>>>> response_dict['status'] = instance.status >>>>> response_dict['address'] = f"{instance.address1}- >>>>> {instance.address2} -{instance.address3} - {instance.address4}" >>>>> return response_dict >>>>> >>>>> I tired that and it's showing me address still in four rows instead of >>>>> one row. >>>>> >>>>> >>>>> On Sun, Oct 18, 2020 at 2:01 PM Etémé Tsanga R. < >>>>> beignethari...@gmail.com> wrote: >>>>> >>>>>> class Meta: >>>>>> model = Application >>>>>> fields = ('id', >>>>>> 'address1','address2','address3','addres4','status') >>>>>> >>>>>> def to_representation(self, instance): >>>>>> response_dict = dict() >>>>>> response_dict['id'] = instance.id >>>>>> response_dict['status'] = instance.status >>>>>> response_dict['address'] = f"{instance.address1}- >>>>>> {instance.address2} >>>>>> -{instance.address3}-{instance.address4}" >>>>>> return response_dict >>>>>> >>>>>> Le dim. 18 oct. 2020 à 09:40, Softtar <softta...@gmail.com> a écrit : >>>>>> >>>>>>> I want to show full address in one row I have four address fields >>>>>>> How i can I do that please. >>>>>>> I tried below code it's not working >>>>>>> >>>>>>> class Meta: >>>>>>> model = Application >>>>>>> fields = ('id', 'address1 + address2 + address3 + addres4','status') >>>>>>> >>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Django REST framework" group. >>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>> send an email to django-rest-framework+unsubscr...@googlegroups.com. >>>>>>> To view this discussion on the web visit >>>>>>> https://groups.google.com/d/msgid/django-rest-framework/93ceeb6a-c7c1-4c7b-834d-81429ef4b0f8n%40googlegroups.com >>>>>>> <https://groups.google.com/d/msgid/django-rest-framework/93ceeb6a-c7c1-4c7b-834d-81429ef4b0f8n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>>> . >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Etémé T. | Software architecture >>>>>> Tel : +237 697-414-835 >>>>>> +237 674-507-065 >>>>>> E-mail : etem...@yahoo.fr >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to a topic in >>>>>> the Google Groups "Django REST framework" group. >>>>>> To unsubscribe from this topic, visit >>>>>> https://groups.google.com/d/topic/django-rest-framework/B71JQxvpRdE/unsubscribe >>>>>> . >>>>>> To unsubscribe from this group and all its topics, send an email to >>>>>> django-rest-framework+unsubscr...@googlegroups.com. >>>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/django-rest-framework/CA%2BBWBj3eHjtt%2BYSMU8DyKF4SBdZ2i0h3KZME1WR_LFTDcQmQeg%40mail.gmail.com >>>>>> <https://groups.google.com/d/msgid/django-rest-framework/CA%2BBWBj3eHjtt%2BYSMU8DyKF4SBdZ2i0h3KZME1WR_LFTDcQmQeg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Django REST framework" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to django-rest-framework+unsubscr...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/django-rest-framework/CAKcjTSOm-%3DJvk9pOJonTNnOxC8%3Dxp6m-S_R1sJKPhUtdwJeZnw%40mail.gmail.com >>>>> <https://groups.google.com/d/msgid/django-rest-framework/CAKcjTSOm-%3DJvk9pOJonTNnOxC8%3Dxp6m-S_R1sJKPhUtdwJeZnw%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> >>>> >>>> -- >>>> Venlig hilsen >>>> Jakob Damgaard Møller >>>> Mobil: 24613112 >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Django REST framework" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/django-rest-framework/B71JQxvpRdE/unsubscribe >>>> . >>>> To unsubscribe from this group and all its topics, send an email to >>>> django-rest-framework+unsubscr...@googlegroups.com. >>>> >>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-rest-framework/CAMmJSsGhC_F7s6PQ616ksez5BH%2Bre%3DU3b4FPYzb1aQGJ3k8F1w%40mail.gmail.com >>>> <https://groups.google.com/d/msgid/django-rest-framework/CAMmJSsGhC_F7s6PQ616ksez5BH%2Bre%3DU3b4FPYzb1aQGJ3k8F1w%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django REST framework" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to django-rest-framework+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-rest-framework/CAKcjTSMd13pJT1%2BxNo7%2BaNXstMyxFyzZLG6WP4EEHSr4XOefog%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-rest-framework/CAKcjTSMd13pJT1%2BxNo7%2BaNXstMyxFyzZLG6WP4EEHSr4XOefog%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> Venlig hilsen >> Jakob Damgaard Møller >> Mobil: 24613112 >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Django REST framework" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/django-rest-framework/B71JQxvpRdE/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> django-rest-framework+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-rest-framework/CAMmJSsHDYtr3i6a893PjEBEvkbwZVeBUrBurZoATMqjGKfgqRQ%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-rest-framework/CAMmJSsHDYtr3i6a893PjEBEvkbwZVeBUrBurZoATMqjGKfgqRQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-rest-framework+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-rest-framework/CAKcjTSOVRXWLcTN65aJRN583t5-X_8XuAi3n-q0JpgvK37xU0w%40mail.gmail.com > <https://groups.google.com/d/msgid/django-rest-framework/CAKcjTSOVRXWLcTN65aJRN583t5-X_8XuAi3n-q0JpgvK37xU0w%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/CA%2BFDnhKB1eSak%2BWQLrj%3DO4PJznprcj5kEU1E7HDjWNb-Qz6rOA%40mail.gmail.com.