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 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/CAMmJSsGhC_F7s6PQ616ksez5BH%2Bre%3DU3b4FPYzb1aQGJ3k8F1w%40mail.gmail.com.

Reply via email to