Skip to main content

Auto create menu base on table values

Project description

DJANGO OUTBOX MENU

Menu is almost use in every web project.

With this library you can create menu for backend and frontend project without headache. All you need to do is:

In your django Environment

Install package to your environment

> pip install django-outbox-menu

Add to INSTALLED_APPS

INSTALLED_APPS = [        
    'django.contrib.sites', 
    'menu',
]

Add SITE_ID in user settings.py

SITE_ID = 1

Include library URLS

urlpatterns += [
    path('', include('menu.urls')),
]

Install requirements

Activate your environment using
> mkvirtualenv env_menu    

Migrate to create table to your database

> python manage.py migrate

In your django Templates

Load menu tags

> {% load menu_tags %}

Generate menu

> {% menu_create FRONTEND 0 as my_menu %}     
syntax :
    > menu_create <menu_kind> <menu_group> as var_name
    > menu_kind  : FRONTEND or BACKEND
    > menu_group : 
        0 : None (use only for FRONTEND)
        1 : Owner
        2 : Manager
        3 : Operator
        4 : Cashier
        etc ... (Update in admin page section [Menu Groups])

> {% for n in my_menu %}
    n have all menu fields such as :
    n.id
    n.parent_id
    n.name
    n.link
    n.icon
    n.is_external
    n.level
    n.haveChild
    n.haveChildEndTag
    You can use it inside for loop

> example in you templates
    <ul class="main-menu">
        {% menu_create FRONTEND 0 as my_menu %}                    
        {% for n in my_menu %}

            {% if forloop.first %}                      
                <li class="main-menu-active">
            {% else %}
                <li>
            {% endif %}

            {% if n.haveChild %}
                <a href="#"> {{n.name}}
                    {% if n.parent_id %}
                        <i class="zmdi zmdi-chevron-right text-to-right"></i>
                    {% endif %}
                </a>
                <ul class="sub-menu">                            
            {% else %}                                
                <a class="clear-content-right" href="#"> {{n.name}} </a>                            
            {% endif %}
                                                            
            
            {% for i in n.haveChildEndTag %}
                <!-- Count = {{forloop.counter}} -->
                {% if forloop.last %}
                    {% if n.parent_id %}
                        </li></ul>
                        {% if not n.haveChild %}                                                
                            </li> <!-- li -->                            
                        {% endif %}  
                    {% else %}
                        </li> <!-- Root -->
                    {% endif %}

                {% else %}
                    </li></ul>
                {% endif %}       

            {% endfor %}                            
                                        
        {% endfor %}                                        
    </ul> 

Run project

> python manage.py runserver
on you browser :
127.0.0.1:8000
127.0.0.1:8000/menu
127.0.0.1:8000/admin

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

authbox-menu-1.0.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

authbox_menu-1.0.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file authbox-menu-1.0.0.tar.gz.

File metadata

  • Download URL: authbox-menu-1.0.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for authbox-menu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b86fe6212a1578c0d40ddb195f29efec8c60f5789192c4a25b27014884e97b6
MD5 efe126d7d793b36bde2202ebd6e82963
BLAKE2b-256 4c2388f58013e5d05ca0ba3bd6166d5c80e2807512055b30c127ab93719b00d9

See more details on using hashes here.

Provenance

File details

Details for the file authbox_menu-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: authbox_menu-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for authbox_menu-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c6e488d5ed311985aab8bce88575589c5adef8e1d1bf2e6bd0a4d5b45de4f1e
MD5 3144aa06ad48d696aebb226dc951c0fc
BLAKE2b-256 5b585b92357d4b612424acd6344a418da14174dc2bdcd678cb108aa0b4bf3f5b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page