### Install Django Daisy from GitHub Source: https://github.com/hypy13/django-daisy/blob/main/README.md This command installs django-daisy directly from its GitHub repository as an editable source. This is useful for development or when you need the latest unreleased features. ```bash pip install -e git+https://github.com/hypy13/django-daisy.git#egg=django-daisy ``` -------------------------------- ### Install Django Daisy via PyPi Source: https://github.com/hypy13/django-daisy/blob/main/README.md This command installs the django-daisy package from the Python Package Index (PyPi). It's the standard way to add the package to your Django project. ```bash pip install django-daisy ``` -------------------------------- ### Django Template for Docutils Installation Prompt Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/missing_docutils.html This Django template snippet displays a message to the user indicating that the docutils library is missing and provides instructions on how to install it, including a link to the docutils project on PyPI. ```Django Template {% extends "admin/base_site.html" %} {% load i18n %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › {% translate 'Documentation' %} {% endblock %} {% block title %}{% translate 'Please install docutils' %}{% endblock %} {% block content %} {% translate 'Documentation' %} =============================== ### {% blocktranslate with "https://docutils.sourceforge.io/" as link %} The admin documentation system requires Python’s [docutils]({{ link }}) library. {% endblocktranslate %} {% blocktranslate with "https://pypi.org/project/docutils/" as link %} Please ask your administrators to install [docutils]({{ link }}). {% endblocktranslate %} {% endblock %} ``` -------------------------------- ### Configure App Settings in apps.py Source: https://github.com/hypy13/django-daisy/blob/main/README.md This example shows how to configure application-specific settings within the `apps.py` file for a Django app. These settings can customize the app's appearance and behavior in the admin sidebar, such as its icon, section title, priority, and visibility. ```python from django.apps import AppConfig class PollsConfig(AppConfig): name = 'polls' # The name of the app icon = 'fa fa-square-poll-vertical' # FontAwesome icon for the app (optional) divider_title = "Apps" # Title of the section divider in the sidebar (optional) priority = 0 # Determines the order of the app in the sidebar (higher values appear first, optional) hide = False # Set to True to hide the app from the sidebar menu (optional) ``` -------------------------------- ### Add Django Daisy to INSTALLED_APPS Source: https://github.com/hypy13/django-daisy/blob/main/README.md After installing django-daisy, you need to add 'django_daisy' and 'django.contrib.humanize' to your Django project's INSTALLED_APPS setting. 'django.contrib.humanize' is a requirement for django-daisy. ```python INSTALLED_APPS = [ 'django_daisy', 'django.contrib.admin', 'django.contrib.humanize', # Required for django-daisy ... ] ``` -------------------------------- ### Django Inline Admin Formset Rendering Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/edit_inline/tabular_flex.html This snippet illustrates the rendering of an inline admin formset in a Django template. It iterates through fields, displays labels, handles readonly fields, and manages delete permissions, incorporating internationalization (i18n) tags. ```django-html {% load dash_tags %} {% load admin_urls %} {% load i18n %} {% trans "Original" %} {% for field in inline_admin_formset.fields %} {% if not field.widget.is_hidden %} {{ field.label|capfirst }} {% endif %} {% endfor %} {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %} {% translate "Delete?" %} {% endif %} {% for inline_admin_form in inline_admin_formset %} {% if inline_admin_form.original or inline_admin_form.show_url %} {{ inline_admin_form.original }} {% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %} [{% if inline_admin_formset.has_change_permission %} {% translate "Change" %} {% else %} {% translate "View" %} {% endif %}] ({% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}) {% endif %} {% else %} - {% endif %} {% for fieldset in inline_admin_form %} {% for line in fieldset %} {% for field in line %} {% if field.is_readonly or not field.field.is_hidden %} {{ field.label_tag|add_class:'label-text !inline-block relative' }} {% if field.is_readonly %} {{ field.contents }} {% else %} {{ field.field }} {% endif %} {% if field.field.errors %} {{ field.field.errors.as_ul }} {% endif %} {% endif %} {% endfor %} {% endfor %} {% endfor %} {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission %} {% if inline_admin_form.original %} {{ inline_admin_form.deletion_field.field }} {% endif %} {% endif %} {% endfor %} ``` -------------------------------- ### Global Django Admin Customizations with DAISY_SETTINGS Source: https://github.com/hypy13/django-daisy/blob/main/README.md Configure project-wide settings for the Django admin interface by defining the `DAISY_SETTINGS` dictionary in `settings.py`. This allows customization of site title, header, index title, logo, styles, scripts, and app ordering. ```python DAISY_SETTINGS = { 'SITE_TITLE': 'Django Admin', 'SITE_HEADER': 'Administration', 'INDEX_TITLE': 'Hi, welcome to your dashboard', 'SITE_LOGO': '/static/admin/img/daisyui-logomark.svg', 'EXTRA_STYLES': [], 'EXTRA_SCRIPTS': [], 'LOAD_FULL_STYLES': False, 'SHOW_CHANGELIST_FILTER': False, 'DONT_SUPPORT_ME': False, 'SIDEBAR_FOOTNOTE': '', 'APPS_REORDER': { 'auth': { 'icon': 'fa-solid fa-person-military-pointing', 'name': 'Authentication', 'hide': False, 'divider_title': "Auth", }, 'social_django': { 'icon': 'fa-solid fa-users-gear', }, }, } ``` -------------------------------- ### Django Template Tag Documentation Structure Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/template_tag_index.html This snippet outlines the structure for documenting Django template tags. It demonstrates how to group tags by library, display tag titles and bodies, and provide instructions for loading tag libraries. ```Django Template {% extends "admin/base_site.html" %} {% load i18n %} {% block title %}{% translate 'Template Tags' %}{% endblock %} {% block content %} {% translate 'Template Tag Documentation' %} ============================================ {% regroup tags|dictsort:"library" by library as tag_libraries %} {% for library in tag_libraries %} {% firstof library.grouper _("Built-in tags") %} ------------------------------------------------- {% if library.grouper %} {% blocktranslate with code="{"|add:"% load "|add:library.grouper|add:" %}" %} To use these tags, put `{{ code }}` in your template before using the tag. {% endblocktranslate %} {% endif %} {% for tag in library.list|dictsort:"name" %} ### {{ tag.name }} #### {{ tag.title|striptags }} {{ tag.body }} {% if not forloop.last %} * * * {% endif %} {% endfor %} {% endfor %} {% endblock %} ``` -------------------------------- ### Django Documentation Bookmarklet Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/bookmarklets.html A JavaScript bookmarklet that allows users to navigate from any page to the documentation for the view that generates that page. It checks for XMLHttpRequest availability and retrieves the 'x-view' header to construct the documentation URL. ```javascript javascript:(function(){if(typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest()}else{return;}x.open('HEAD',location.href,false);x.send(null);try{view=x.getResponseHeader('x-view')}catch(e){alert('No view found for this page');return;}if(view=='undefined'){alert('No view found for this page')}document.location='{% url 'django-admindocs-views-index' %}'+view+'/'}) ``` -------------------------------- ### Django Admin Base Site Template Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/bookmarklets.html An HTML template extending the Django admin's base site, used for displaying documentation-related content, including bookmarklet instructions and links. ```html {% extends "admin/base_site.html" %} {% load i18n %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) › {% translate 'Bookmarklets' %} {% endblock %} {% block title %}{% translate 'Documentation Bookmarklets' %}{% endblock %} {% block content %} {% blocktranslate %} To install bookmarklets, drag the link to your bookmarks toolbar, or right-click the link and add it to your bookmarks. You can now select the bookmarklet from any page in the site. {% endblocktranslate %} ### [{% translate "Documentation for this page" %}](javascript:(function(){if(typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest()}else{return;}x.open('HEAD',location.href,false);x.send(null);try{view=x.getResponseHeader('x-view')}catch(e){alert('No view found for this page');return;}if(view=='undefined'){alert('No view found for this page')}document.location='{% url 'django-admindocs-views-index' %}'+view+'/') {% translate "Jumps you from any page to the documentation for the view that generates that page." %} {% endblock %} ``` -------------------------------- ### JavaScript Theme and Color Scheme Management Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/base.html This snippet includes a JavaScript function to detect the user's preferred color scheme (dark or light) using `window.matchMedia`. It also handles setting the theme in local storage and applying it to the document's data-theme attribute. Includes logic for language switching within a Django form. ```javascript function getSystemColorScheme() { try { if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { return 'dark'; } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) { return 'light'; } else { return 'light'; // In case the user's preference is not explicitly set. } } catch (e) { return 'light' } } document.documentElement.setAttribute( 'data-theme', localStorage.getItem('theme') || getSystemColorScheme() ) function switchLanguage(elem) { let lang_id = $(elem).find('span.lang-id').html(); $("form#setlang input[name='language']").val(lang_id); $("form#setlang").submit(); } ``` -------------------------------- ### Django Template Actions Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/actions.html Demonstrates the usage of Django template tags for actions, including loading custom tags, internationalization, and rendering form fields and submit buttons. ```HTML {% load dash_tags %} {% load i18n %} {% block actions %} {% trans "Action" %}: {% block actions-form %} {% for field in action_form %} {% if field.label %} {{ field.label }} {{ field }} {% endif %} {% endfor %} {% endblock %} {% block actions-submit %} {% translate "Go" %} {% endblock %} {% endblock %} ``` -------------------------------- ### Django Template Filter Documentation Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/template_filter_index.html This snippet details the structure for documenting Django template filters. It shows how to group filters by library, provide instructions for loading them, and list individual filters with their names, titles, and descriptions. ```Django Template {% extends "admin/base_site.html" %} {% load i18n %} {% block coltype %}colSM{% endblock %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) › {% translate 'Filters' %} {% endblock %} {% block title %}{% translate 'Template Filters' %}{% endblock %} {% block content %} {% translate 'Template Filter Documentation' %} =============================================== {% regroup filters|dictsort:"library" by library as filter_libraries %} {% for library in filter_libraries %} {% firstof library.grouper _("Built-in filters") %} ---------------------------------------------------- {% if library.grouper %} {% blocktranslate with code="{"|add:"% load "|add:library.grouper|add:" %"|add:"}" %} To use these filters, put `{{ code }}` in your template before using the filter. {% endblocktranslate %} * * * {% endif %} {% for filter in library.list|dictsort:"name" %} ### {{ filter.name }} {{ filter.title }} {{ filter.body }} {% if not forloop.last %} * * * {% endif %} {% endfor %} {% endfor %} {% endblock %} {% block sidebar %} {% regroup filters|dictsort:"library" by library as filter_libraries %} {% for library in filter_libraries %} {% firstof library.grouper _("Built-in filters") %} ---------------------------------------------------- {% for filter in library.list|dictsort:"name" %}* [{{ filter.name }}](#{{ library.grouper|default:""}}) {% endfor %} {% endfor %} {% endblock %} ``` -------------------------------- ### Django App and Model Navigation Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/parts/app_list.html This snippet generates a navigable list of Django applications and their models, including links to the admin interface for each model. It handles nested applications and models with single or multiple entries. ```Django Template {% for app in app_list %} {% if app.apps %} * [{{ app.name }}](#) {% for app in app.apps %} * {% if app.models|length == 1 %} [{{ app.models.0.name }}]({{ app.models.0.admin_url }}) {% else %} [{{ app.name }}](#) {% for model in app.models %} * [{{ model.name }}]({{ model.admin_url }}) {% endfor %} {% endif %} {% endfor %} {% else %} * {% if app.models|length == 1 %} [{{ app.name }}]({{ app.models.0.admin_url }}) {% else %} [{{ app.name }}](#) {% for model in app.models %} * [{{ model.name }}]({{ model.admin_url }}) {% endfor %} {% endif %} {% endif %} {% endfor %} ``` -------------------------------- ### Django Template Rendering and Search Path Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/template_detail.html This snippet demonstrates how Django templates are rendered, including breadcrumbs, page titles, and the search path for a specific template. It shows the use of Django's template tags for internationalization and URL generation. ```django {% extends "admin/base\_site.html" %} {% load i18n %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) › {% translate 'Templates' %} › {{ name }} {% endblock %} {% block title %}{% blocktranslate %}Template: {{ name }}{% endblocktranslate %}{% endblock %} {% block content %} {% blocktranslate %}Template: {{ name }}{% endblocktranslate %} =============================================================== {% blocktranslate %}Search path for template {{ name }}:{% endblocktranslate %} ------------------------------------------------------------------------------- {% for template in templates|dictsort:"order" %}1. `{{ template.file }}` {% if not template.exists %} _{% translate '(does not exist)' %}_ {% endif %} {% endfor %} [‹ {% translate 'Back to Documentation' %}]({% url 'django-admindocs-docroot' %}) {% endblock %} ``` -------------------------------- ### Django Template Structure and Content Blocks Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/base.html This snippet outlines the basic structure of a Django template, including blocks for title, body font, extra head content, extra styles, navigation sidebar, top navbar, content title, breadcrumbs, and the main content area. It also shows how to include messages and custom script links. ```django {% load i18n %} {% load static %} {% load dash_tags %} {% get_current_language as LANGUAGE_CODE %} {% get_current_language_bidi as LANGUAGE_BIDI %} {% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %} {% if CUSTOM_DAISYUI_BUILD_PATH %} {% endif %} {% if LOAD_FULL_STYLES %} {% else %} {% endif %} {% block body_font %} /* CSS font definitions */ {% endblock %} {% block extrahead %}{% endblock %} {% block extrastyle %}{% endblock %} {% for custom_style_link in EXTRA_STYLES %} {% endfor %} {% if not is_popup and is_nav_sidebar_enabled %} {% block nav-sidebar %} {% include "admin/parts/sidebar.html" with app_list=available_apps %} {% endblock %} {% endif %} {% block top-navbar %} {% if not is_popup %} {% include 'admin/parts/navbar.html' %} {% endif %} {% endblock %} {% block breadcrumbs %}{% endblock %} {% block content %} {{ content }} {% endblock %} {% if change_language_url %} {% csrf_token %} {% endif %} {% block messages %} {% if messages %} {% for message in messages %} {{ message|capfirst }} {% endfor %} {% endif %} {% endblock messages %} {% for custom_script_link in EXTRA_SCRIPTS %} {% endfor %} {% block scripts %}{% endblock %} ``` -------------------------------- ### Django Model Documentation Template Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/model_detail.html This snippet shows the Django template structure used to render model documentation, including fields and methods. It utilizes Django's template tags for internationalization and URL generation. ```Django Template {% extends "admin/base\_site.html" %} {% load i18n %} {% block extrahead %} {{ block.super }} .module table { width: 100%; } .module table p { padding: 0; margin: 0; } {% endblock %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) [{% translate 'Models' %}]({% url 'django-admindocs-models-index' %}) {{ name }} {% endblock %} {% block title %}{% blocktranslate %}Model: {{ name }}{% endblocktranslate %}{% endblock %} {% block content %} {{ name }} ========== {{ summary }} ------------- {{ description }} ### {% translate 'Fields' %} {% for field in fields|dictsort:"name" %} {% endfor %} {% translate 'Field' %} {% translate 'Type' %} {% translate 'Description' %} {{ field.name }} {{ field.data\_type }} {{ field.verbose }}{% if field.help\_text %} - {{ field.help\_text|safe }}{% endif %} {% if methods %} ### {% translate 'Methods with arguments' %} {% for method in methods|dictsort:"name" %} {% endfor %} {% translate 'Method' %} {% translate 'Arguments' %} {% translate 'Description' %} {{ method.name }} {{ method.arguments }} {{ method.verbose }} {% endif %} [‹ {% translate 'Back to Model documentation' %}]({% url 'django-admindocs-models-index' %}) {% endblock %} ``` -------------------------------- ### Django Admin Base Site Extension Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/view_detail.html Extends the Django admin base site template to display documentation details for views. It includes breadcrumbs, view name, summary, body, context, and template information. ```Django Template {% extends "admin/base\_site.html" %} {% load i18n %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) › [{% translate 'Views' %}]({% url 'django-admindocs-views-index' %}) › {{ name }} {% endblock %} {% block title %}{% blocktranslate %}View: {{ name }}{% endblocktranslate %}{% endblock %} {% block content %} {{ name }} ========== {{ summary|striptags }} ----------------------- {{ body }} {% if meta.Context %} ### {% translate 'Context:' %} {{ meta.Context }} {% endif %} {% if meta.Templates %} ### {% translate 'Templates:' %} {{ meta.Templates }} {% endif %} [‹ {% translate 'Back to View documentation' %}]({% url 'django-admindocs-views-index' %}) {% endblock %} ``` -------------------------------- ### CSS Font Face Definitions Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/base.html This snippet defines custom font faces for use in the project. It includes a font for right-to-left text ('rtl-font') using Vazir.woff2 and the 'body-font' using Ubuntu, with definitions for regular and bold weights. ```css @font-face { font-family: 'rtl-font'; src: url("{% static 'admin/fonts/Vazir.woff2' %}") format('woff'); font-weight: normal; font-style: normal; } @font-face { font-family: 'body-font'; src: local('Ubuntu'), local('Ubuntu-Regular'), url("{% static 'admin/fonts/Ubuntu/Ubuntu-Regular.ttf' %}") format('truetype'); font-weight: normal; font-style: normal; } /* Bold */ @font-face { font-family: 'body-font'; src: local('Ubuntu-Medium'), url("{% static 'admin/fonts/Ubuntu/Ubuntu-Medium.ttf' %}") format('truetype'); font-weight: bold; font-style: normal; } ``` -------------------------------- ### Django Template Tag Sidebar Navigation Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/template_tag_index.html This snippet shows how to generate a sidebar navigation for Django template tags, linking to each tag's documentation section. ```Django Template {% block sidebar %} {% regroup tags|dictsort:"library" by library as tag_libraries %} {% for library in tag_libraries %} {% firstof library.grouper _("Built-in tags") %} ------------------------------------------------- {% for tag in library.list|dictsort:"name" %}* [{{ tag.name }}](#{{ library.grouper|default:""|lower|replace:" ","-"|slugify }}{{ tag.name|lower|replace:" ","-"|slugify }}) {% endfor %} {% endfor %} {% endblock %} ``` -------------------------------- ### Django Pagination Tags Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/pagination.html Demonstrates the use of Django template tags for rendering pagination links, including previous, next, and individual page number links. It also handles the display of the total number of results and an option to show all results. ```Django Template {% load dash_tags %} {% load admin_list %} {% load i18n %} {% if pagination_required and cl.page_num > 1 %} [{% trans "Previous" }]({% get_page_link cl cl.page_num|add:'-1' %}) {% endif %} {% if pagination_required and cl.page_num < cl.paginator.num_pages %} [{% trans "Next" }]({% get_page_link cl cl.page_num|add:'1' %}) {% endif %} {% if pagination_required %} {% for i in page_range %} {% if i == cl.page_num %} {{ i }} {% else %} [{{ i }}]({% get_page_link cl i %}) {% endif %} {% endfor %} {% endif %} {{ cl.result_count }} {% if cl.result_count == 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endif %} [{% if cl.full_result_count != cl.result_count %} {% if cl.show_full_result_count %} {% blocktranslate with full_result_count=cl.full_result_count %}{{ full_result_count }} total {% endblocktranslate %} {% else %} {% translate "Show all" %} {% endif %} {% endif %}](? {% if cl.is_popup %}{{ is_popup_var }}=1{% if cl.add_facets %}&{% endif %}{% endif %} {% if cl.add_facets %}{{ is_facets_var }}{% endif %}) ``` -------------------------------- ### Django File Input Widget with Custom Classes Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/django/forms/widgets/clearable_file_input.html This snippet demonstrates how to load Django template tags and apply a series of Tailwind CSS classes to a file input widget. It includes logic to display the initial file if it exists and handles optional clearing of the file input. ```django-template {% load dash_tags %} {% with widget=widget|apply_class_to_widget:'file-input file-input-bordered file-input-sm w-full max-w-xs focus:outline-0 transition-all focus:outline-offset-0' %} {% if widget.is_initial %} {{ widget.initial_text }}: [{{ widget.value }}]({{ widget.value.url }}) {% if not widget.required %} {{ widget.clear_checkbox_label }} {% endif %} {{ widget.input_text }}: {% endif %} {% endwith %} ``` -------------------------------- ### Django Template Filters and Logic Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/change_list_results.html Demonstrates the usage of Django template tags for loading static files, internationalization, and managing active filters. It also shows how to render form errors and iterate through results, including conditional display based on sortable headers and filter counts. ```Django Template {% load i18n %} {% load dash_tags %} {% get_active_filters_count cl as active_filters_count %} {% if result_hidden_fields %} {# DIV for HTML validation #} {% for item in result_hidden_fields %}{{ item }}{% endfor %} {% endif %} {% if result.form and result.form.non_field_errors %} {{ result.form.non_field_errors }} {% endif %} {% for header in result_headers %} {% endfor %} {% for result in results %} {% if result.form and result.form.non_field_errors %} {% endif %} {% for item in result %}{{ item|safe }}{% endfor %} {% empty %} {% endfor %} {% if header.sortable and header.sort_priority > 0 %} []({{ header.url_remove }} "{% translate " {% endif %} {% if header.sortable %} [{{ header.text|capfirst }}]({{ header.url_primary }}) {% else %} {{ header.text|capfirst }} {% endif %} {% if header.sortable and header.sort_priority > 0 %} []({{ header.url_toggle }} "{% translate " {% if num_sorted_fields > 1 %} {{ header.sort_priority }} {% endif %} {% endif %} {{ result.form.non_field_errors }} {% trans "Empty Result" %} {% if active_filters_count or cl.query %} [{% trans "Clear all filters" %}](?) {% endif %} ``` -------------------------------- ### Add Item Navigation Tool (Django Template) Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/list_navigate_tools.html This snippet demonstrates how to conditionally display an 'Add' link in Django's admin interface navigation tools. It uses the `has_add_permission` flag and the `admin_urlname` tag to generate the correct URL for adding new items, preserving existing filters and popup states. ```Django Template {% load i18n admin_urls %} {% block navigte_tools %} {% if has_add_permission %} {% url cl.opts|admin_urlname:'add' as add_url %} [{% blocktranslate with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktranslate %}]({% add_preserved_filters add_url is_popup to_field %}) {% endif %} {% endblock %} ``` -------------------------------- ### Django Dashboard Template Structure Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/index.html This snippet shows the basic structure of the Django dashboard template, including extending the base site template, loading static files and tags, and defining content blocks for the title and main content. It utilizes Django's template language for dynamic content rendering and internationalization. ```html {% extends "admin/base\_site.html" %} {% load humanize %} {% load dash\_tags %} {% load i18n %} {% block content_title %} {{ index_title|default:"Django Daisy Dashboard" }} {% endblock %} {% block content %} {% trans "History" %} [{% trans "Show all" %}]({{ logentry_changelist_url }}) {% for history in latest\_history %} {% endfor %} {% trans "In" %} {% trans "Action" %} {% trans "At Time" %} {% trans "Admin" %} [{{ history.content_type }}]({{ history.get_admin_url }}) [{{ history.get_action_flag_display }}]({% url 'admin:admin_logentry_change' history.pk %}) {{ history.action_time|naturaltime }} **[{{ history.user }}]({% get_user_admin_change_url history.user %})** {% endblock %} ``` -------------------------------- ### Render Django Formset with Daisy Theme Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/django/forms/formsets/div.html This snippet shows the standard Django template code for rendering a formset, assuming the forms are configured to use the Daisy UI framework. It includes the necessary management form and iterates through each form, rendering it as a div. ```Django Template {{ formset.management_form }}{% for form in formset %}{{ form.as_div }}{% endfor %} ``` -------------------------------- ### Django Admin Base Site Template Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/view_index.html Extends the base Django admin site template to customize the layout and breadcrumbs for the documentation section. ```html {% extends "admin/base\_site.html" %} {% load i18n %} {% block coltype %}colSM{% endblock %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) › {% translate 'Views' %} {% endblock %} {% block title %}{% translate 'Views' %}{% endblock %} {% block content %} {% translate 'View Documentation' %} ==================================== {% regroup views|dictsort:'namespace' by namespace as views\_by\_ns %} {% translate 'Jump to Namespace' %} ----------------------------------- {% for ns\_views in views\_by\_ns %}* [{% if ns\_views.grouper %}{{ ns\_views.grouper }} {% else %}{% translate "Empty namespace" %}{% endif %}](#ns|{{ ns\_views.grouper }}) {% endfor %} {% for ns\_views in views\_by\_ns %} {% if ns\_views.grouper %} {% blocktranslate with ns\_views.grouper as name %}Views by namespace {{ name }}{% endblocktranslate %} {% else %} {% blocktranslate %}Views by empty namespace{% endblocktranslate %} {% endif %} ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {% for view in ns\_views.list|dictsort:"url" %} {% ifchanged %} ### [{{ view.url }}]({% url 'django-admindocs-views-detail' view=view.full_name %}) {% blocktranslate with view.full\_name as full\_name and view.url\_name as url\_name %} View function: `{{ full_name }}`. Name: `{{ url_name }}`. {% endblocktranslate %} {{ view.title }} * * * {% endifchanged %} {% endfor %} {% endfor %} {% endblock %} ``` -------------------------------- ### Django Model Documentation Generation Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/model_index.html This snippet demonstrates how Django's template system is used to generate documentation for models. It utilizes template tags like 'extends', 'load', 'block', 'regroup', and 'url' to structure and link model information. ```Django Template {% extends "admin/base\_site.html" %} {% load i18n %} {% block coltype %}colSM{% endblock %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › [{% translate 'Documentation' %}]({% url 'django-admindocs-docroot' %}) › {% translate 'Models' %} {% endblock %} {% block title %}{% translate 'Models' %}{% endblock %} {% block content %} {% translate 'Model Documentation' %} ===================================== {% regroup models by app\_config as grouped\_models %} {% for group in grouped\_models %} {{ group.grouper.verbose\_name }} ({{ group.grouper.name }}) ------------------------------------------------------------ {% for model in group.list %} {% endfor %} [{{ model.object\_name }}]({% url 'django-admindocs-models-detail' app_label=model.app_label model_name=model.model_name %}) {% endfor %} {% endblock %} {% block sidebar %} {% translate 'Model Groups' %} ------------------------------ {% regroup models by app\_config as grouped\_models %} {% for group in grouped\_models %}* [{{ group.grouper.verbose\_name }}](#app-{{ group.grouper.label }}) {% endfor %} {% endblock %} ``` -------------------------------- ### Enable Language Change in Django Admin Source: https://github.com/hypy13/django-daisy/blob/main/README.md Steps to enable language switching in the Django admin panel. This involves modifying the `urls.py` to include Django's internationalization URLs and ensuring `LocaleMiddleware` is active in `settings.py`. Supported languages are also defined in `settings.py`. ```Python from django.urls import path, include urlpatterns = [ ..., path("i18n/", include("django.conf.urls.i18n")), ] ``` ```Python MIDDLEWARE = [ ..., 'django.middleware.locale.LocaleMiddleware', ... ] ``` ```Python LANGUAGES = [ ('en', 'English'), ('fa', 'Farsi'), # Add other languages as needed ] ``` -------------------------------- ### Render Django Formset Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/django/forms/formsets/p.html This snippet illustrates the standard Django template code for rendering a formset. It includes the mandatory management form and iterates over each form in the formset, rendering it using `as_p`. ```Django Template {{ formset.management_form }}{% for form in formset %}{{ form.as_p }}{% endfor %} ``` -------------------------------- ### Initialize Tokenfield with Django Widget Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/django/forms/widgets/comma_seperate.html This snippet demonstrates how to initialize a tokenfield component using jQuery when a Django widget is ready. It targets an input element associated with a specific Django widget name. ```JavaScript {% load static %} $(document).ready(function () { $('input[name="{{ widget.name }}"]').tokenfield() }) ``` -------------------------------- ### Creating Tabbed Inline Admin in Django Source: https://github.com/hypy13/django-daisy/blob/main/README.md Implement tabbed inline administration for Django models by extending `NavTabMixin` in your inline admin classes. This allows related models to be displayed in a tabbed format within the main model's admin view. ```python from django_daisy.mixins import NavTabMixin class ChoiceInline(admin.TabularInline, NavTabMixin): model = Choice extra = 1 @admin.register(Poll) class PollAdmin(admin.ModelAdmin): inlines = [ChoiceInline] ``` -------------------------------- ### Making Admin Fieldsets Navigable Tabs in Django Source: https://github.com/hypy13/django-daisy/blob/main/README.md Configure Django admin fieldsets to appear as navigation tabs by adding the `navtab` class to the `classes` attribute of the fieldset definition in your `admin.py` file. This enhances form organization and user experience. ```python @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin): fieldsets = ( (None, { 'fields': ('username', 'password') }), (_('Personal info (tabbed example)'), { 'fields': ( 'first_name', 'last_name', 'email', ), 'classes': ('navtab',), }), (_('No tabbed example'), { 'fields': ( 'is_active', 'is_staff', 'is_superuser', ), }), ) ``` -------------------------------- ### Django Admin Login Form Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/login.html Renders the admin login form with username and password fields. Includes error handling for invalid credentials and provides a link for password reset. ```html {% extends "admin/base.html" %} {% load dash_tags %} {% load i18n static %} {% block extrastyle %}{% endblock %} {% block bodyclass %}{{ block.super }} login{% endblock %} {% block usertools %}{% endblock %} {% block nav-global %}{% endblock %} {% block nav-sidebar %}{% endblock %} {% block content_title %}{% endblock %} {% block nav-breadcrumbs %}{% endblock %} {% block top-navbar %} {% endblock %} {% block content %} {% if form.errors and not form.non_field_errors %} {% blocktranslate count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %} {% endif %} {% if form.non_field_errors %} {% for error in form.non_field_errors %} {{ error }} {% endfor %} {% endif %} {% translate "Admin Login" %} ----------------------------- {% if user.is_authenticated %} {% blocktranslate trimmed %} You are authenticated as {{ username }}, but are not authorized to access this page. Would you like to login to a different account? {% endblocktranslate %} {% endif %} {% csrf_token %} {{ form.username.errors }} {{ form.username.label }} {{ form.username|add_class:"input input-bordered w-full" }} {{ form.password.errors }} {{ form.password.label }} {{ form.password|add_class:"input input-bordered w-full" }} {% url 'admin_password_reset' as password_reset_url %} {% if password_reset_url %} [{% translate 'Forgotten your password or username?' %}]({{ password_reset_url }}) {% endif %} {% translate 'Log in' %} {% endblock %} ``` -------------------------------- ### Django Template Tags and Filters Documentation Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin_doc/index.html Provides an overview of Django template tags and filters, explaining their purpose and how they can be used to manipulate variables and extend template functionality. ```Django Template {% extends "admin/base_site.html" %} {% load i18n %} {% block breadcrumbs %} [{% translate 'Home' %}]({% url 'admin:index' %}) › {% translate 'Documentation' %} {% endblock %} {% block title %}{% translate 'Documentation' %}{% endblock %} {% block content %} {% translate 'Documentation' %} =============================== [{% translate 'Tags' %}](tags/) ------------------------------- {% translate 'List of all the template tags and their functions.' %} [{% translate 'Filters' %}](filters/) ------------------------------------- {% translate 'Filters are actions which can be applied to variables in a template to alter the output.' %} [{% translate 'Models' %}](models/) ----------------------------------- {% translate 'Models are descriptions of all the objects in the system and their associated fields. Each model has a list of fields which can be accessed as template variables.' %} [{% translate 'Views' %}](views/) --------------------------------- {% translate 'Each page on the public site is generated by a view. The view defines which template is used to generate the page and which objects are available to that template.' %} [{% translate 'Bookmarklets' %}](bookmarklets/) ----------------------------------------------- {% translate 'Tools for your browser to quickly access admin functionality.' %} {% endblock %} ``` -------------------------------- ### Render Django Formset with Daisy Theme Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/django/forms/formsets/ul.html This snippet illustrates the standard Django way to render a formset, including the essential management form and then iterating through each form in the formset to render its fields. This is typically used within an HTML template. ```django-html {{ formset.management_form }}{% for form in formset %}{{ form.as_ul }}{% endfor %} ``` -------------------------------- ### Django Admin Changelist Form Handling and Search Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/change_list.html Manages formset errors, displays the search form, handles admin actions, and includes object tools. It also integrates pagination and filtering mechanisms. ```html {% get_active_filters_count cl as active_filters_count %} {% if cl.formset and cl.formset.errors %} {% if cl.formset.total_error_count %} {% blocktranslate count counter=cl.formset.total_error_count %} Please correct the error below. {% plural %} Please correct the errors below. {% endblocktranslate %} {% for error in cl.formset.non_form_errors %}* {{ error }} {% endfor %} {% endif %} {% endif %} {% search_form cl %} {% csrf_token %} {% block search %}{% search_form cl %}{% endblock %} {% if action_form and actions_on_top and cl.show_admin_actions %} {% admin_actions %} {% endif %} {% block object-tools %} {% if cl.list_editable %} {% trans "Save" %} {% endif %} {% block object-tools-items %} {% change_list_object_tools %} {% endblock %} {% endblock %} {% if cl.formset %} {{ cl.formset.management_form }} {% endif %} {% block result_list %} {% result_list cl %} {% endblock %} {% block pagination %}{% pagination cl %}{% endblock %} ``` -------------------------------- ### Django Admin Filtering and TomSelect Integration Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/change_list.html Implements a filtering system for the Django admin changelist, allowing users to select filter options. It uses TomSelect for enhanced dropdowns and includes JavaScript for dynamic filter updates and search submission. ```html {% if cl.has_filters %} {% translate "Filter" %} ------------------------ {% trans "Filter" %} {% if cl.is_facets_optional or active_filters_count %} {% if cl.is_facets_optional %} {% if cl.add_facets %} {% translate "Show counts" %} {% else %} {% translate "Show counts" %} {% endif %} {% endif %} {% if active_filters_count %} ### [{% translate "Clear all filters" %}](?) {% endif %} {% endif %} {% for spec in cl.filter_specs %} {% admin_list_filter cl spec request %} {% endfor %} {% endif %} {% block scripts %} {{ block.super }} {% endblock %} ``` -------------------------------- ### Django Message Display Source: https://github.com/hypy13/django-daisy/blob/main/django_daisy/templates/admin/parts/messages.html This snippet shows how to display messages in a Django template. It iterates through a list of messages and capitalizes the first letter of each message. ```Django Template {% block messages %} {% if messages %} {% for message in messages %} {{ message|capfirst }} {% endfor %} {% endif %} {% endblock messages %} ```