You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79-36Lines changed: 79 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,9 +61,13 @@ Did you decide to start using Unfold but you don't have time to make the switch
61
61
-[Numeric filters](#numeric-filters)
62
62
-[Date/time filters](#datetime-filters)
63
63
-[Custom admin pages](#custom-admin-pages)
64
-
-[Nonrelated inlines](#nonrelated-inlines)
65
64
-[Display decorator](#display-decorator)
66
65
-[Change form tabs](#change-form-tabs)
66
+
-[Inlines](#inlines)
67
+
-[Custom title](#custom-title)
68
+
-[Hide title row](#hide-title-row)
69
+
-[Display as tabs](#display-as-tabs)
70
+
-[Nonrelated inlines](#nonrelated-inlines)
67
71
-[Third party packages](#third-party-packages)
68
72
-[django-celery-beat](#django-celery-beat)
69
73
-[django-guardian](#django-guardian)
@@ -751,41 +755,6 @@ The template is straightforward, extend from `unfold/layouts/base.html` and the
751
755
{% endblock %}
752
756
```
753
757
754
-
## Nonrelated inlines
755
-
756
-
To display inlines which are not related (no foreign key pointing at the main model) to the model instance in changeform, you can use nonrelated inlines which are included in `unfold.contrib.inlines` module. Make sure this module is included in `INSTALLED_APPS` in settings.py.
757
-
758
-
```python
759
-
from django.contrib.auth.models import User
760
-
from unfold.admin import ModelAdmin
761
-
from unfold.contrib.inlines.admin import NonrelatedTabularInline
762
-
from .models import OtherModel
763
-
764
-
classOtherNonrelatedInline(NonrelatedTabularInline): # NonrelatedStackedInline is available as well
765
-
model = OtherModel
766
-
fields = ["field1", "field2"] # Ignore property to display all fields
767
-
768
-
defget_form_queryset(self, obj):
769
-
"""
770
-
Gets all nonrelated objects needed for inlines. Method must be implemented.
771
-
"""
772
-
returnself.model.objects.all()
773
-
774
-
defsave_new_instance(self, parent, instance):
775
-
"""
776
-
Extra save method which can for example update inline instances based on current
777
-
main model object. Method must be implemented.
778
-
"""
779
-
pass
780
-
781
-
782
-
@admin.register(User)
783
-
classUserAdmin(ModelAdmin):
784
-
inlines = [OtherNonrelatedInline]
785
-
```
786
-
787
-
**NOTE:** credit for this functionality goes to [django-nonrelated-inlines](https://github.com/bhomnick/django-nonrelated-inlines)
788
-
789
758
## Display decorator
790
759
791
760
Unfold introduces it's own `unfold.decorators.display` decorator. By default it has exactly same behavior as native `django.contrib.admin.decorators.display` but it adds same customizations which helps to extends default logic.
@@ -912,6 +881,44 @@ class MyModelAdmin(ModelAdmin):
912
881
)
913
882
```
914
883
884
+
## Inlines
885
+
886
+
### Custom title
887
+
888
+
By default, the title available for each inline row is coming from the `__str__` implementation of the model. Unfold allows you to override this title by implementing `get_inline_title` on the model which can return your own custom title just for the inline.
889
+
890
+
```python
891
+
from unfold.admin import TabularInline
892
+
893
+
894
+
classUser(models.Model):
895
+
# fiels, meta ...
896
+
897
+
defget_inline_title(self):
898
+
return"Custom title"
899
+
900
+
901
+
classMyInline(TabularInline):
902
+
model = User
903
+
```
904
+
905
+
### Hide title row
906
+
907
+
By applying `hide_title` attribute set to `True`, it is possible to hide the title row which is available for `StackedInline` or `TabularInline`. For `StackedInline` it is required to have disabled delete permission `can_delete` to be able to hide the title row, because the checkbox with the delete action is inside this title.
908
+
909
+
```python
910
+
# admin.py
911
+
912
+
from unfold.admin import TabularInline
913
+
914
+
915
+
classMyInline(TabularInline):
916
+
model = User
917
+
hide_title =True
918
+
```
919
+
920
+
### Display as tabs
921
+
915
922
Inlines can be grouped into tab navigation by specifying `tab` attribute in the inline class.
916
923
917
924
```python
@@ -925,6 +932,42 @@ class MyInline(TabularInline):
925
932
tab =True
926
933
```
927
934
935
+
### Nonrelated inlines
936
+
937
+
To display inlines which are not related (no foreign key pointing at the main model) to the model instance in changeform, you can use nonrelated inlines which are included in `unfold.contrib.inlines` module. Make sure this module is included in `INSTALLED_APPS` in settings.py.
938
+
939
+
```python
940
+
from django.contrib.auth.models import User
941
+
from unfold.admin import ModelAdmin
942
+
from unfold.contrib.inlines.admin import NonrelatedTabularInline
943
+
from .models import OtherModel
944
+
945
+
classOtherNonrelatedInline(NonrelatedTabularInline): # NonrelatedStackedInline is available as well
946
+
model = OtherModel
947
+
fields = ["field1", "field2"] # Ignore property to display all fields
948
+
949
+
defget_form_queryset(self, obj):
950
+
"""
951
+
Gets all nonrelated objects needed for inlines. Method must be implemented.
952
+
"""
953
+
returnself.model.objects.all()
954
+
955
+
defsave_new_instance(self, parent, instance):
956
+
"""
957
+
Extra save method which can for example update inline instances based on current
958
+
main model object. Method must be implemented.
959
+
"""
960
+
pass
961
+
962
+
963
+
@admin.register(User)
964
+
classUserAdmin(ModelAdmin):
965
+
inlines = [OtherNonrelatedInline]
966
+
```
967
+
968
+
**NOTE:** credit for this functionality goes to [django-nonrelated-inlines](https://github.com/bhomnick/django-nonrelated-inlines)
{% for inline_admin_form in inline_admin_formset %}
18
18
<divclass="inline-related group inline-stacked {% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form last-related{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
19
-
<h3class="bg-gray-50 border-b {% if not forloop.first %}border-t{% endif %} border-gray-200 flex font-medium items-center mb-3 px-3 py-2 text-gray-400 text-sm dark:bg-white/[.02] dark:border-gray-800">
{% include "unfold/helpers/messages/error.html" with errors=inline_admin_form.form.non_field_errors %}
62
70
63
71
{% for fieldset in inline_admin_form %}
64
-
<divclass="px-3 -mb-5">
72
+
<divclass="px-3 -mb-5 {% if inline_admin_formset.opts.hide_title %}{% if not inline_admin_formset.formset.can_delete or not inline_admin_formset.has_delete_permission %}pt-3{% endif %}{% endif %}">
65
73
{% include 'admin/includes/fieldset.html' with stacked=1 %}
0 commit comments