carltongibson / neapolitan

Quick CRUD views for Django
https://noumenal.es/neapolitan/
MIT License
413 stars 30 forks source link

Not sure on how to change the Role for each view? #32

Closed bingimar closed 2 months ago

bingimar commented 9 months ago

can someone explain how to change the Role for each view? I'd like to make some views only list and detail.

carltongibson commented 9 months ago

Hi @bingimar.

I need to make this easier, or at least documented better, but the base approach would be to override get_urls(). Something like...

    @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

…will give you just the list and detail views.

carltongibson commented 2 months ago

Fixed in 24.4 You can now do something like:

    urlpatterns = [
        *BookmarkView.get_urls(roles={Role.LIST, Role.DETAIL}),
    ]