These are chat archives for django/django

Feb 2016
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,

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

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

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

    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
        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)
            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
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): ...
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
Feb 04 2016 13:00
@sboudouk I literally just said that :)
join #restframework here
Feb 04 2016 13:01
Thanks !
Sorry i didn't read history
Filip Figiel
Feb 04 2016 13:01
you're welcome
Omar Quimbaya
Feb 04 2016 14:28
Hey everyone! I'm looking forward to the django discussions on here.
Filip Figiel
Feb 04 2016 14:28
Omar Quimbaya
Feb 04 2016 14:29
Thank you! I hope to contribute when I c
Filip Figiel
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
Feb 04 2016 16:57
In the search_fields = ('author', 'title', 'published_date',) is not working, can anyone help me to resolve it ? thanks advance
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
Feb 04 2016 19:07
Anyone been using django-redis with Django 1.9?