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

How do I register my dashboard class ? #8

Open
erewh0 opened this issue Jul 31, 2023 · 5 comments
Open

How do I register my dashboard class ? #8

erewh0 opened this issue Jul 31, 2023 · 5 comments

Comments

@erewh0
Copy link

erewh0 commented Jul 31, 2023

Hi :)

Docs say that after creating my dashboards.py file I need to register your dashboard class in order for it to work with the auto urls..... What exactly do I need to do ? ( am a newbie so prbably a dumb q but.... )

I have a Django app running and would like to add a Dashboard to it... have tried install into that app and also an install into a demo project,. Am blocked at this step ... thanks

Mike

@jdwpeterson
Copy link
Contributor

Hi Mike,

Thanks for getting in touch. Basically all you need to do to register your dashboard is add

registry.register(DashboardClassName)

to to bottom of your dashboards.py file. Where DashboardClassName is the Dashboard you have created.

You need to do this for every dashboard you create. So if you had 2 dashboards, DashboardOne and DashboardTwo, set up you would add:

registry.register(DashboardOne)
registry.register(DashboardTwo)

Your final dashboards.py file should then look something like:

from dashboards.dashboard import Dashboard
from dashboards.component import Text, Chart
from dashboards.registry import registry

from demo.mydashboard.data import DashboardData


class FirstDashboard(Dashboard):
    welcome = Text(value="Welcome to Django Dashboards!")
    animals = Chart(defer=DashboardData.fetch_animals)

    class Meta:
        name = "First Dashboard"


registry.register(FirstDashboard)

I hope this helps but if not, or you have any further questions please get back in touch.

@erewh0
Copy link
Author

erewh0 commented Aug 1, 2023 via email

@erewh0
Copy link
Author

erewh0 commented Aug 1, 2023 via email

@jdwpeterson
Copy link
Contributor

Hi Mike,

It's hard to tell but looks like maybe your virtual env isn't active or using a different one when running the code.

If you run pip freeze do you see django-dashboards listed?

How are you running the code? Is it command line or via a code editor like VS Code?

You also sent your folder structure but the formatting seems to have messed up. Could you send it again and also show where the manage.py, settings.py and urls.py files live.

@erewh0
Copy link
Author

erewh0 commented Aug 2, 2023 via email

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