Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create @route decorator for adding additional routes to CRUDView #61

Open
joshuadavidthomas opened this issue Nov 14, 2023 · 4 comments

Comments

@joshuadavidthomas
Copy link
Member

No description provided.

@carltongibson
Copy link

Yes, something here. See also my comment on westerveltco/neapolitan#4.

@joshuadavidthomas
Copy link
Member Author

joshuadavidthomas commented Feb 7, 2024

I actually have an implementation of this. I spent a little bit of time after writing this issue smashing the bits of DRF's ViewSet into CRUDView to see if I could get this working. It's not pretty and it pretty much copies DRF wholesale, but it does work.

https://gist.github.com/joshuadavidthomas/cca48d87caf9c0637a750eea5ae9f6a9

@joshuadavidthomas
Copy link
Member Author

My memory is a bit fuzzy, but if I remember correctly my use case was I wanted a way to hang a few routes off of a CRUDView for easy HTMX related stuff and not have to muddy up the various dispatch methods.

@carltongibson
Copy link

I think this is related to carltongibson/neapolitan#32.

There I give the example overriding get_urls():

    @classonlymethod
    def get_urls(cls):
        verbose_name = cls.model._meta.model_name
        urlpatterns = [
            path(
                f"{verbose_name}/",
                cls.as_view(role=Role.LIST),
                name=f"{verbose_name}-list",
            ),
            path(
                f"{verbose_name}/<int:pk>/",
                cls.as_view(role=Role.DETAIL),
                name=f"{verbose_name}-detail",
            ),
        return urlpatterns

This to limit the exposed routes, but I'm doing the same urlpatterns.extend() to add extra actions (using a CustomRole class) currently.

There's a bunch of related work here, but I think the endpoint likely is a decorator.

@joshuadavidthomas joshuadavidthomas transferred this issue from westerveltco/neapolitan Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants