Skip to content

Commit efbc2c3

Browse files
authored
feat: django-modeltranslation admin tabs support (#244)
1 parent ad4752c commit efbc2c3

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,21 @@ class ExampleAdmin(ModelAdmin, ImportExportModelAdmin):
653653

654654
### django-modeltranslation
655655

656-
By default Unfold does not contain any specific implementation for django-modeltranslation and the application is partially supported. Basic behavior is supported except of tab navigation provided by django-modeltranslation. At the moment there are no plans in supporting this behavior.
656+
By default, Unfold supports django-modeltranslation and `TabbedTranslationAdmin` admin class for the tabbed navigation is implemented with custom styling as well.
657+
658+
```python
659+
from django.contrib import admin
660+
661+
from modeltranslation.admin import TabbedTranslationAdmin
662+
from unfold.admin import ModelAdmin
663+
664+
from .models import MyModel
665+
666+
667+
@admin.register(MyModel)
668+
class MyModelAdmin(ModelAdmin, TabbedTranslationAdmin):
669+
pass
670+
```
657671

658672
For django-modeltranslation fields for spefic languages, it is possible to define custom flags which will appear as a suffix in field's label. It is recommended to use emojis as suffix.
659673

src/unfold/static/unfold/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/unfold/styles.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,26 @@ trix-toolbar[id^="trix-toolbar-"] {
586586
.trix-active {
587587
@apply text-primary-600;
588588
}
589+
590+
/*******************************************************
591+
django-modeltranslation
592+
*******************************************************/
593+
.ui-tabs {
594+
@apply flex flex-col;
595+
}
596+
597+
.ui-tabs.ui-widget .ui-tabs-nav {
598+
@apply bg-gray-100 border-0 flex gap-2 m-0 mb-4 mr-auto p-1 rounded text-sm dark:bg-white/[.04] after:hidden;
599+
}
600+
601+
.ui-tabs.ui-widget .ui-tabs-nav li {
602+
@apply border-0 top-0;
603+
}
604+
605+
.ui-tabs.ui-widget .ui-tabs-nav li a {
606+
@apply bg-transparent border-0 flex flex-row font-medium items-center m-0 px-2.5 py-1 rounded text-gray-400 text-sm hover:bg-gray-700/[.04] hover:text-gray-700 dark:hover:bg-white/[.04] dark:hover:text-white;
607+
}
608+
609+
.ui-tabs.ui-widget .ui-tabs-nav li.ui-tabs-active a {
610+
@apply flex flex-row font-medium items-center px-2.5 py-1 rounded bg-white shadow-sm text-gray-700 hover:bg-white dark:bg-gray-900 dark:hover:bg-gray-900 dark:text-white;
611+
}

src/unfold/templates/admin/includes/fieldset.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2 class="bg-gray-100 border border-transparent font-semibold mb-6 px-4 py-3 ro
1515

1616
<div class="aligned border border-gray-200 mb-8 rounded-md pt-3 px-3 shadow-sm dark:border-gray-800">
1717
{% for line in fieldset %}
18-
<div class="block {% if not line.fields|length_is:'1' %}flex flex-row flex-wrap gap-x-8 {% else %}block {% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
18+
<div class="form-row block {% if not line.fields|length_is:'1' %}flex flex-row flex-wrap gap-x-8{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
1919
{% for field in line %}
2020
<div class="flex group {% if field.errors %}errors {% endif %}{% if not line.fields|length_is:1 %}lg:max-w-xs w-full {% endif %}{% if not forloop.parentloop.last %} mb-6 {% else %} mb-3{% endif %} {% if row %}flex-row items-center{% else %}flex-col{% endif %}">
2121
{% if field.is_checkbox %}

0 commit comments

Comments
 (0)