Giter Site home page Giter Site logo

Viewset support about django-rest-framework-bulk HOT 8 CLOSED

bufke avatar bufke commented on September 29, 2024
Viewset support

from django-rest-framework-bulk.

Comments (8)

eftechnologies avatar eftechnologies commented on September 29, 2024

That would be awesome.

from django-rest-framework-bulk.

eftechnologies avatar eftechnologies commented on September 29, 2024

I am going to be taking a look at it in the next week.

from django-rest-framework-bulk.

kevin-brown avatar kevin-brown commented on September 29, 2024

While I haven't tried it out, this should be supported if you do not use routers. When initializing the urlpattern, you would just need to link the post/put/patch/delete views using as_view(). Modifying the routers to make it work there is a different story of course, as you would have to override the list route.

from django-rest-framework-bulk.

thomasWajs avatar thomasWajs commented on September 29, 2024

It totally work as expected, I've been able to setup a BulkUpdateViewSet with straightforward mixins :

class UserViewSet(BulkUpdateModelMixin, viewsets.ModelViewSet):
    model = User

class BulkUpdateRouter(DefaultRouter):
    routes = SimpleRouter.routes
    routes[0] = Route(
        url=r'^{prefix}{trailing_slash}$',
        mapping={
            'get': 'list',
            'post': 'create',
            'put': 'bulk_update',
            'patch': 'partial_bulk_update'
        },
        name='{basename}-list',
        initkwargs={'suffix': 'List'}
    )

router = BulkUpdateRouter()
router.register(r'users', UserViewSet)

Adding DELETE would be a breeze as well (but I don't need it)

from django-rest-framework-bulk.

miki725 avatar miki725 commented on September 29, 2024

👍 @thomasWajs
I actually never needed to use ViewSets for my projects since I needed fine-grained control and making APIViews did not seem so difficult. Thanx for posting example of how to integrate with ViewSets. If you want, you can add this into Readme and submit PR.

from django-rest-framework-bulk.

ashleyblackmore avatar ashleyblackmore commented on September 29, 2024

@thomasWajs if possible, can you please add an example of a request that can be made against bulk_update, or partial_bulk_update? I'm a bit baffled by this. Thank you!

from django-rest-framework-bulk.

thomasWajs avatar thomasWajs commented on September 29, 2024

PATCH /users/?is_admin=1
is_staff=1

Would do a partial update on all user that are admin, to set them staff as well.
The filtering mechanism uses the one builtin rest-framework, which relies on django-filter

from django-rest-framework-bulk.

ashleyblackmore avatar ashleyblackmore commented on September 29, 2024

Thank you so much!

from django-rest-framework-bulk.

Related Issues (20)

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.