These are chat archives for django/django

4th
Feb 2016
kdelinx
@kdelinx
Feb 04 2016 12:09

Hi, i wrote some serializers, but when i send POST query, i get just one field - {'sex': 0}

class UserTouristSerializer(serializers.ModelSerializer):

    birthday = serializers.SerializerMethodField()
    first_name = serializers.SerializerMethodField()
    middle_name = serializers.SerializerMethodField()
    last_name = serializers.SerializerMethodField()
    passports = PassportTouristSerializer(many=True,
                                          required=False,
                                          allow_null=True)

    @staticmethod
    def get_first_name(obj):
        return translit(obj.first_name, reversed=True)

    @staticmethod
    def get_middle_name(obj):
        return translit(obj.middle_name, reversed=True)

    @staticmethod
    def get_last_name(obj):
        return translit(obj.last_name, reversed=True)

    @staticmethod
    def get_birthday(obj):
        return int(format(obj.birthday, 'U'))'

    def create(self, validated_data):
        qs_create = {}
        for key, value in validated_data.items():
            if key != '' and value is not None:
                qs_create[key] = value
                print(qs_create)
        return Tourist.objects.create(**qs_create)

    def update(self, instance, validated_data):
        for field in self.fields:
            instance.field = validated_data.get(field.__str__(), instance.field)
            instance.save()
            return instance

    class Meta:
        model = Tourist
        fields = ('id', 'first_name', 'middle_name', 'passports',
                  'last_name', 'sex', 'birthday',)

I think, that i take mistake with @staticmethod functions, because without them, i take correctly answer.
What should i do?

Filip Figiel
@megapctr
Feb 04 2016 12:36
@kdelinx you should join #restframework on freenode to get help from DRF developers
and yes, you probably should use instance methods instead
so def get_last_name(self, obj): ...
Sami
@sboudouk
Feb 04 2016 12:59
Hello bros
I'm using Django REST Framework and need a little bit help. Any idea on where I can get this ?
Filip Figiel
@megapctr
Feb 04 2016 13:00
@sboudouk I literally just said that :)
join #restframework here https://webchat.freenode.net/
Sami
@sboudouk
Feb 04 2016 13:01
Thanks !
Sorry i didn't read history
Filip Figiel
@megapctr
Feb 04 2016 13:01
you're welcome
np
Omar Quimbaya
@WritingPanda
Feb 04 2016 14:28
Hey everyone! I'm looking forward to the django discussions on here.
Filip Figiel
@megapctr
Feb 04 2016 14:28
welcome!
Omar Quimbaya
@WritingPanda
Feb 04 2016 14:29
Thank you! I hope to contribute when I c
Can*
Filip Figiel
@megapctr
Feb 04 2016 14:37
you can type s/tpyo/typo/ and gitter will replace your last message :)
this, or with an :arrow_up: key
Rana
@ranafge
Feb 04 2016 16:57
In the admin.py search_fields = ('author', 'title', 'published_date',) is not working, can anyone help me to resolve it ? thanks advance
Rana
@ranafge
Feb 04 2016 17:19
During reading a post i want to suggest some popular article to user to read, how can i do this?
Amir Rustamzadeh
@amirrustam
Feb 04 2016 19:07
Anyone been using django-redis with Django 1.9?