|
| 1 | +# Guides |
| 2 | + |
| 3 | +## General Option |
| 4 | + |
| 5 | +dynamic setup your site base on table `django_admin_settings_options`. |
| 6 | + |
| 7 | +support options: |
| 8 | + |
| 9 | +- Site Title |
| 10 | +- Site Header |
| 11 | +- Site Logo |
| 12 | +- Welcome Sign |
| 13 | + |
| 14 | +## Options |
| 15 | + |
| 16 | +this options in your db, named `django_admin_settings_options`, after do migrate. |
| 17 | + |
| 18 | +you can also add your custom option into this table, and use it by templatetags |
| 19 | + `adminlte_options` with function `get_adminlte_option`. |
| 20 | + |
| 21 | +options table has a valid field to control your option work or not. |
| 22 | + |
| 23 | + |
| 24 | +example: |
| 25 | + |
| 26 | +``` |
| 27 | +# adminlte/general_option.html |
| 28 | +
|
| 29 | +{% load adminlte_options %} |
| 30 | +
|
| 31 | +# here my option_name is site_title, you can custom yourself. |
| 32 | +{% get_adminlte_option 'site_title' as adminlte_site_title %} |
| 33 | +{% if adminlte_site_title.valid %} |
| 34 | +{{ adminlte_site_title.site_title }} |
| 35 | +{% else %} |
| 36 | +{{ site_title|default:_('Django site admin') }} |
| 37 | +{% endif %} |
| 38 | +
|
| 39 | +``` |
| 40 | + |
| 41 | +before custom option, you should known what adminlte has used. |
| 42 | + |
| 43 | +- site_title |
| 44 | +- site_header |
| 45 | +- site_logo |
| 46 | +- welcome_sign |
| 47 | + |
| 48 | +## Widgets |
| 49 | + |
| 50 | +### AdminlteSelect |
| 51 | + |
| 52 | +example: |
| 53 | +``` |
| 54 | +# adminlte/admin.py |
| 55 | +@admin.register(Menu) |
| 56 | +class MenuAdmin(TreeAdmin): |
| 57 | + ... |
| 58 | + change_form_template = 'adminlte/menu_change_form.html' |
| 59 | + formfield_overrides = { |
| 60 | + models.ForeignKey: {'widget': AdminlteSelect} |
| 61 | + } |
| 62 | +
|
| 63 | +# adminlte/menu_change_form.html |
| 64 | +# active the target select |
| 65 | +{% extends 'admin/change_form.html' %} |
| 66 | +
|
| 67 | +{% block extrajs %} |
| 68 | +{{ block.super }} |
| 69 | +<script> |
| 70 | + django.jQuery('#id_content_type').select2(); |
| 71 | +</script> |
| 72 | +{% endblock %} |
| 73 | +``` |
| 74 | +effect: |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +### AdminlteSelectMultiple |
| 79 | + |
| 80 | +example: |
| 81 | +``` |
| 82 | +# adminlte/admin.py |
| 83 | +@admin.register(Menu) |
| 84 | +class MenuAdmin(TreeAdmin): |
| 85 | + ... |
| 86 | + change_form_template = 'adminlte/menu_change_form.html' |
| 87 | + formfield_overrides = { |
| 88 | + # multiple for ManayToManyField |
| 89 | + models.ManayToManyField: {'widget': AdminlteSelectMultiple( |
| 90 | + attr={'style': 'width: 100%'} |
| 91 | + )} |
| 92 | + } |
| 93 | +
|
| 94 | +# adminlte/menu_change_form.html |
| 95 | +# active the target select |
| 96 | +{% extends 'admin/change_form.html' %} |
| 97 | +
|
| 98 | +{% block extrajs %} |
| 99 | +{{ block.super }} |
| 100 | +<script> |
| 101 | + django.jQuery('#id_content_type').select2(); |
| 102 | +</script> |
| 103 | +{% endblock %} |
| 104 | +``` |
| 105 | +effect: |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +## Menu |
| 112 | + |
| 113 | +developing ... |
0 commit comments