unfoldadmin / django-unfold

Modern Django admin theme for seamless interface development
https://unfoldadmin.com
MIT License
1.82k stars 186 forks source link

Custome Page not working #748

Closed hernansaa closed 4 weeks ago

hernansaa commented 1 month ago

What version of Unfold are you using?

For example: 0.38

What version of Django are you using?

For example: 5.0.6

Did you checked changelog/commit history, if the bug is not already fixed?

For example: Yes

Did you searched other issues, if the bug is not already fixed?

For example: Yes

Did you checked documentation?

Yes.

Describe your issue

Not 100 per cent sure is a bug or is just me, being me. When trying to create a Custom Page, it seems that the url is not being registered. I have tried different patterns but the urlconf doesn't seem to be aware of the url. I am using a custom admin (https://unfoldadmin.com/blog/migrating-django-admin-unfold/) and its being working well, But I just cant make the custom page work. Any help would be greatly appreciated. Thanks.

admin.py


class MyClassBasedView(UnfoldModelAdminViewMixin, TemplateView):
    title = "Custom Title"  # required: custom page header title
    permission_required = () # required: tuple of permissions
    template_name = "admin/quotations/test.html"

@register(Quotation, site=new_admin_site)
class CustomAdmin(ModelAdmin):
    def get_urls(self):
        return super().get_urls() + [
            path(
                "test/",
                MyClassBasedView.as_view(model_admin=self),  # IMPORTANT: model_admin is required
                name="custom_name"
            ),
        ]

I get a Page not found and no trace of the "test/" url. image

lukasvinclav commented 1 month ago

Hey, I just followed the docs and implemented custom page in the Formula (demo) project without any issues. If you can replicate the issue in separate repository, let me know here and I will check that. Soon, I will update Formula so you will be able to play with the code locally.

hernansaa commented 1 month ago

Hey, I just followed the docs and implemented custom page in the Formula (demo) project without any issues. If you can replicate the issue in separate repository, let me know here and I will check that. Soon, I will update Formula so you will be able to play with the code locally.

Hola! thanks a lot for the quick response. I have created a new repo to test it (https://github.com/hernansaa/test-custom-page). Also I have created a new app in the django project called "testpage", where I configure de admin.py and template as per the documentation. The project hast a app called "core" which has the settings.py in it. Also, has a gs_admin app where all the configuration for the unfold admin is (loaders.py, sites.py). I hope this is enough for you to check it, otherwise let me know and will do whatever you need. Thanks a lot in advance.

gadonski commented 1 month ago

Hey, I just followed the docs and implemented custom page in the Formula (demo) project without any issues. If you can replicate the issue in separate repository, let me know here and I will check that. Soon, I will update Formula so you will be able to play with the code locally.

Hola! thanks a lot for the quick response. I have created a new repo to test it (https://github.com/hernansaa/test-custom-page). Also I have created a new app in the django project called "testpage", where I configure de admin.py and template as per the documentation. The project hast a app called "core" which has the settings.py in it. Also, has a gs_admin app where all the configuration for the unfold admin is (loaders.py, sites.py). I hope this is enough for you to check it, otherwise let me know and will do whatever you need. Thanks a lot in advance.

try this:

on you custom url set the path without slash

@register(Quotation, site=new_admin_site)

class CustomAdmin(ModelAdmin):
    def get_urls(self):
        return super().get_urls() + [
            path(
               "test",
                MyClassBasedView.as_view(model_admin=self),  # IMPORTANT: model_admin is required
                name="custom_name"
            ),
        ]

in you browser, try the addres with the app name / model name / custom address, eg:

lukasvinclav commented 4 weeks ago

Hey, here is an example code how to get it done:

https://github.com/unfoldadmin/formula/blob/main/src/formula/admin.py#L408-L415

hernansaa commented 1 week ago

Hey, here is an example code how to get it done:

https://github.com/unfoldadmin/formula/blob/main/src/formula/admin.py#L408-L415

Lukas, I have been busy these weeks but I am sure it will work. Thanks a lot!