estebistec / drf-compound-fields

Django-REST-framework serializer fields for compound types.
BSD 3-Clause "New" or "Revised" License
92 stars 12 forks source link

Add PartialDictField #8

Closed sonnyhu closed 10 years ago

sonnyhu commented 10 years ago

Hi, great work! I have been using a customized DictField which will include part of dict if users specify included_keys = []. The motivation is that for a django's json field [https://bitbucket.org/schinckel/django-jsonfield/], I only want to return part of the data inside of that field. I am not sure if you are ok if I create a pull request for this. Thanks.

estebistec commented 10 years ago

@SonnyHu Let me have a look at it and I'll let you know if it would fit later tonight. Thanks!

sonnyhu commented 10 years ago

@estebistec Thanks! If you think it would be fit, I will go ahead wrap my code up.

estebistec commented 10 years ago

Thinking on this some more, wouldn't you be relying on some integration with models using that field? On it's own, it wouldn't help you with that field, right?

sonnyhu commented 10 years ago

I agree with you. But it will depend on model only when it is used, the field itself will not depend on model. output = PartialDictField(included_keys=['key1', 'key2']), then key1 and key2 will be in that model's field, but PartialDictField only need to iterate over that field to extract data according to included_keys without knowing what exactly is in that model's field. Hope this helps. Thanks.

estebistec commented 10 years ago

okay, so regardless of the integration you want to be able to give such a field a full dict and have some keys filtered out.

sonnyhu commented 10 years ago

Yeah, that's what I am thinking.

estebistec commented 10 years ago

Go ahead and make the pull. I imagine by sub-classing DictField, you'll just have a minimal part to handle included_keys in the field from_native/to_native methods.

sonnyhu commented 10 years ago

Thanks. I will make a pull request this weekend.

sonnyhu commented 10 years ago

Hi, I just created a pull request for PartialDictField. Please review it. Honestly, this is my first time submit a pull request for an open source repo. So comments and suggestions are more than welcome. Thanks.

estebistec commented 10 years ago

Pull was merged in, so closing this

estebistec commented 10 years ago

@SonnyHu Decided to go ahead and cut an initial pre-release, so have at it! :P https://pypi.python.org/pypi/drf-compound-fields/0.1.0

sonnyhu commented 10 years ago

Yes!!!!!