Code Monkey home page Code Monkey logo

django-rest-framework-dyn-serializer's People

Contributors

cybergrind avatar lezeroq avatar nepherhotep avatar radyz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-rest-framework-dyn-serializer's Issues

field_name.context = self.context AttributeError: can't set attribute

Hello,

I am using Django rest framework 3.6.4 and I am getting the following error:

File "/home/vagrant/.virtualenvs/api/lib/python3.6/site-packages/rest_framework_dyn_serializer.py", line 44, in init
field_name.context = self.context
AttributeError: can't set attribute

I think that the error is related to the following change in the version 3.6.4:

encode/django-rest-framework@563020e

You can see in the line 599 that @cached_property is not longer used, and it was replaced for @Property, I think that the (for in ) in line https://github.com/Nepherhotep/django-rest-framework-dyn-serializer/blob/master/rest_framework_dyn_serializer.py#L43 is not need anymore, but I am not totally sure.

Regards.

All nested serializers ignore `limit_fields = False`

Here is an example taken from test with a little change

# Pass limit_fields = False to nested serializer
class ArticleDynSerializer(DynModelSerializer):
    author = AuthorDynSerializer(required=False, limit_fields=False)

    class Meta:
        model = Article
        fields_param = 'article_fields'
        fields = ['id', 'title', 'created', 'updated', 'content', 'author']

class ArticleViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Article.objects.all().order_by('id')

    def get_serializer(self, *args, **kwargs):
        context = self.get_serializer_context()
        context['request'] = self.request
        s = ArticleDynSerializer(*args, context=context, limit_fields=True, **kwargs)
        return s

In such case author serializer behaves like dynamic in spite of limit_fields is set to False. So all fields for nested serializers always must be defined explicitly in the request.

Limit fields during declaration

Is it possible to limit fields when declared so that a model serializer can be re-used, e.g:

UserModelSerializer(fields=('id', 'first_name', 'last_name',))

This way I can re-use the UserModelSerializer in other places without exposing additional info such as username, email etc when nesting it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.