Live data from Hacker News

Django REST framework 2.3 released: ViewSets and Routers

django-rest-framework.org

31–37 of 37 posts

Re: Django REST framework 2.3 released: ViewSets and Routers

#31

Earlier quoted context omitted.

I'm actively using both frameworks on separate projects and have roughly 1 year of experience with Tastypie and 2 months of experience with DRF. Both have strengths and weaknesses with very similar feature sets, although I personally prefer DRF, backed up by my choice to use it over Tastypie when starting a new project 2 months ago. Tastypie has a rather monolithic structure (most of the logic is wrapped in a single…

The ability in 2.3 to use multiple filter backends is partly intended to address queryset permissions adequately. It means you can setup a filter backend to deal with any permissions-based filtering, while still including client-determined field filtering/searching etc...

Nice, I didn't recognize you could use multiple default filter backends glancing at the 2.3 documentation. That would provide a means of addressing the main concern - creating a reusable object that could be applied to any api view that filters the queryset in a predefined way (eg: limit the queryset to objects owned by the current user). Another point for DRF.

Re: Django REST framework 2.3 released: ViewSets and Routers

#32
I feel very comfortable with Tastypie, and have pretty well internalized its API. I've got most custom code down to muscle memory. Because of this I don't feel constrained by Tastypie at all.

That said it is very "Django"-y, meaning it's got a high level of abstraction, very opinionated but provides hooks for everything. It's also pays a huge amount of attention to testing.

All that aside I did evaluate DRF for my last project. Tastypie's Django 1.5 support didn't exist, it had some weird interaction issues with our database setup, and it has a huge amount of outstanding issues & pull requests. I spent like 2 days working with DRF and it felt clumsy for me (read: not objectively clumsy, I was just used to thinking about exposing data to a hypermedia API in a particular way). Honestly I just got annoyed by the CBV part. I know some people love them and I'm sure they're great and all, just wasn't for me.

edit: frankly they're doing the same thing, they're both well-written and -maintained. It's just about which API you prefer to work with.

Re: Django REST framework 2.3 released: ViewSets and Routers

#33
post #14

Earlier quoted context omitted.

The Rest Framework is a lot more flexible and just don't get into your way when you need your API to do anything else than exposing CRUD operations. The whole design of DRF makes a lot more sense for my use cases. TastyPie provides you with Resources that do everything from accepting and dispatching methods, querying db, authentication and authorization to parsing an serializing data. If you want to modify one puzzle…

It feels like DRF is trying to do too much. I'm not a fan of Django's generic views for much the same reason. I really wanted a framework that was as easy to use as plain Django views while still handling the REST heavy lifting. So I made Delicious Cake: https://github.com/pretend-money/delicious-cake It's based on Tastypie, but features a complete Resource re-design that moves serialization and validation out of the…

The philosophy behind this looks similar to a library created by a co-worker of mine that we use extensively internally:

https://github.com/bruth/restlib2

Re: Django REST framework 2.3 released: ViewSets and Routers

#34
I am fairly fluent with django class based views and tastypie, but i can't help but feel this sort of OO design has a painful learning curve. you basically need to dig through the stack of classes, mixins, etc pretty comprehensively to get a sense of how everything fits together. once you understand the flow, it's fine. But I find myself wishing there was a map (and one embodied in the code, not external documentation). Does anyone recognize this feeling and if so do you have any thoughts?

Re: Django REST framework 2.3 released: ViewSets and Routers

#35
post #34

I am fairly fluent with django class based views and tastypie, but i can't help but feel this sort of OO design has a painful learning curve. you basically need to dig through the stack of classes, mixins, etc pretty comprehensively to get a sense of how everything fits together. once you understand the flow, it's fine. But I find myself wishing there was a map (and one embodied in the code, not external documentatio…

http://ccbv.co.uk/

That site helped a lot when I was first getting the gist of CBVs. Browsing Django's source for the views was surprisingly unpainful, and doing that was aided by iPython's introspection capabilities (typing ?? after an object will show you the source of the class).

Re: Django REST framework 2.3 released: ViewSets and Routers

#36

I feel very comfortable with Tastypie, and have pretty well internalized its API. I've got most custom code down to muscle memory. Because of this I don't feel constrained by Tastypie at all. That said it is very "Django"-y, meaning it's got a high level of abstraction, very opinionated but provides hooks for everything. It's also pays a huge amount of attention to testing. All that aside I did evaluate DRF for my la…

> Honestly I just got annoyed by the CBV part.

There's a bunch of things in 2.3 that should make working with the CBVs a much more pleasant experience.

* There's no longer any inheritance from Django's GCBV machinery, specifically SingleObjectMixin, and MultipleObjectMixin. The base class was simple enough that it wasn't really necessary. That means no more browsing across multiple codebases, and less class hierarchy to think about.

* Previously there were three base classes, now there's just a single simplified GenericAPIView.

* Several attributes and methods have been moved to pending deprecation or refactored and simplified.

* Using ViewSets means less verbose, repeated view code and easier URL configuration.

Additionally, all the changes are covered by the deprecation policy, so upgrading from 2.2 should be seamless, despite the tweaks to the GCBV implementation.

Re: Django REST framework 2.3 released: ViewSets and Routers

#37
post #34

I am fairly fluent with django class based views and tastypie, but i can't help but feel this sort of OO design has a painful learning curve. you basically need to dig through the stack of classes, mixins, etc pretty comprehensively to get a sense of how everything fits together. once you understand the flow, it's fine. But I find myself wishing there was a map (and one embodied in the code, not external documentatio…

http://ccbv.co.uk/ That site helped a lot when I was first getting the gist of CBVs. Browsing Django's source for the views was surprisingly unpainful, and doing that was aided by iPython's introspection capabilities (typing ?? after an object will show you the source of the class).

wow, thanks for posting this! Very impressive resource. I was trying to speak more to the general challenge of learning this sort of OO system (I pretty much learned class based views by reading the code already), but I'm happy that you shared this, I will pass it on to others.
Post reply on HN