compact_inline.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ==============
  2. Compact Inline
  3. ==============
  4. By default Django admin interface provides two types of inlines to edit models on the same page as a
  5. related model – ``StackedInline`` and ``TabularInline``. ``StackedInline`` is mostly used when there are
  6. not so many objects. If number of models is rather big, ``TabularInline`` can help you. Unfortunately when
  7. related model has a lot of fields it may be not convenient to interact with them.
  8. To solve this problem JET has a ``CompactInline`` class built-in.
  9. .. image:: _static/compact_inline.png
  10. :width: 100%
  11. Usage
  12. -----
  13. ``CompactInline`` works exactly like Django built-in inlines, you need just
  14. to inherit ``jet.admin.CompactInline`` inline class. That's all.
  15. .. code:: python
  16. from django.contrib import admin
  17. from people.models import County, State, City
  18. from jet.admin import CompactInline
  19. class StateCountiesInline(admin.TabularInline):
  20. model = County
  21. extra = 1
  22. show_change_link = True
  23. class StateCitiesInline(CompactInline):
  24. model = City
  25. extra = 1
  26. show_change_link = True
  27. class StateAdmin(admin.ModelAdmin):
  28. inlines = (StateCountiesInline, StateCitiesInline)