# Django Jet

***

**1. Customize Dashboard Header**

```python
# settings.py
JET_DASHBOARD_HEADER = (
    '<h1> My Dashboard </h1>',  # header markup
    ' Welcome to Django Jet! ',  # header text
)
```

**2. Configure Homepage**

```python
# settings.py
JET_INDEX_DASHBOARD = 'dashboard.Dashboard'  # custom dashboard name
```

**3. Override Default App Icons**

```python
# settings.py
JET_DEFAULT_APP_ICONS = {
    'polls': 'fas fa-poll-h',
    'auth': 'fas fa-id-card',
}
```

**4. Customize Menu Items**

```python
# admin.py
from jet.models import ModelLink

class MyModelLink(ModelLink):
    index = 300

    def render(self, request, context):
        # customize link display
        return '<a class="row-link" href="

<div data-gb-custom-block data-tag="url" data-0='admin:%s_%s_change'></div>?order=<div data-gb-custom-block data-tag="url" data-0='admin:%s_%s_changelist'></div>

&field=created"> Latest </a>'
```

**5. Enable History Panel**

```python
# settings.py
JET_SIDE_MENU_COMPACT = True
JET_CHANGE_FORM_SIDESHOW = True
```

**6. Customize Admin Template**

```python
# templates/admin/base_site.html

<div data-gb-custom-block data-tag="extends" data-0='admin/base_site.html'></div>

`

<div data-gb-custom-block data-tag="load"></div>`
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="<div data-gb-custom-block data-tag="static" data-0='jet/css/admin-lte.css'></div>" />
    </head>
    <body class="hold-transition skin-purple sidebar-mini">
        <div data-gb-custom-block data-tag="block"></div>

    </body>
</html>
```

**7. Use Side Menu Switcher**

```python

<div data-gb-custom-block data-tag="load"></div>

<div data-gb-custom-block data-tag="jet_sidebar_switcher" data-width='200px'></div>

```

**8. Embed Tabular Inline**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    inlines = [TabularInline, InlineWithForeignKeys]
```

**9. Configure Inline Detail View**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        StackedInline(model=Book, verbose_name='Books', verbose_name_plural='Books'),
    ]
```

**10. Add Foreign Key Widget**

```python
# models.py
class Book(models.Model):
    title = models.CharField(max_length=200)
    author = models.ForeignKey('Author', on_delete=models.CASCADE)
```

**11. Configure Foreign Key Widget**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    formfield_overrides = {
        Author._meta.get_field('author').remote_field: {
            'widget': ForeignKeyRawIdWidget(Author, site)
        }
    }
```

**12. Display Related Objects**

```python
# models.py
class Book(models.Model):
    title = models.CharField(max_length=200)
    authors = models.ManyToManyField('Author')
```

**13. Override Changelist Title**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    changelist_title = 'Authors List'
```

**14. Disable Inline Addition**

```python
# admin.py
class BookInline(admin.TabularInline):
    can_add = False
```

**15. Limit Inline Display**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    inlines = (BookInline,)
    inline_formats = (
        # Add "tabular" inline in the form of a table
        ("tabular", 'Books', BookInline, 1),
    )
```

**16. Customize Inline Ordering**

```python
# admin.py
class BookInline(admin.TabularInline):
    ordering = ('title',)
```

**17. Use Simple List Filter**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    list_filter = ('surname',)
```

**18. Add Related Field Filter**

```python
# admin.py
class BookAdmin(admin.ModelAdmin):
    list_filter = ('authors__name',)
```

**19. Configure Filter Options**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    list_filter = (
        ('surname', admin.EmptyChoiceField(choices=[('1', 'A'), ('2', 'B'), ('3', 'C')])),
    )
```

**20. Use Date Hierarchy**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    date_hierarchy = 'created_at'
```

**21. Enable Search Fields**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    search_fields = ('name', 'surname')
```

**22. Override List View**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    def changelist_view(self, request, extra_context=None):
        # Override the changelist view
        extra_context.update({'foo': 'bar'})
        return super(AuthorAdmin, self).changelist_view(request, extra_context)
```

**23. Customize Form Field**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.CharField: {'widget': forms.TextInput(attrs={'placeholder': 'Enter text here...'})}
    }
```

**24. Create Custom Action**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    def send_email(self, request, queryset):
        # Send email to selected authors
        pass

    send_email.short_description = 'Send Email'
    actions = ['send_email']
```

**25. Override Admin Actions**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    actions = ['delete_selected']

    def delete_selected(self, request, queryset):
        # Delete selected authors
        pass

    def has_delete_permission(self, request, obj=None):
        # Check if user has permission to delete objects
        return False
```

**26. Configure Bootstrap Dropdowns**

```python
# settings.py
JET_SIDE_MENU_ITEMS = [
    {
        'label': 'Profile',
        'icon': 'fas fa-user',
        'items': [
            {'label': 'Settings', 'url': '/profile/settings/', 'icon': 'fas fa-cog'},
            {'label': 'Logout', 'url': '/accounts/logout/', 'icon': 'fas fa-sign-out-alt'},
        ]
    },
]
```

**27. Use Jet Login Page**

```python
# settings.py
JET_LOGIN_FORM = 'path.to.MyLoginForm'
JET_LOGIN_LOGO = 'path/to/logo.png'
JET_LOGIN_LOGO_ALT = 'My logo'
```

**28. Customize Sidebar Footer**

```python
# settings.py
JET_SIDE_MENU_FOOTER = 'Powered by Django Jet'
```

**29. Configure Related Links**

```python
# admin.py
class BookAdmin(admin.ModelAdmin):
    related_links = [
        {
            'url': '/books/1',
            'label': 'Book 1',
        },
    ]
```

**30. Display Form Actions**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    actions_on_top = True
    actions_on_bottom = True
```

**31. Use Jet Tag Filter Widget**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    list_filter = (('tags', JetTagFilterWidget),)
```

**32. Configure Admin Page Title**

```python
# settings.py
JET_SITE_TITLE = 'My Django Jet Admin'
```

**33. Override Model Admin Class**

```python
# admin.py
from jet.admin import CompactInline

class BookInline(CompactInline):
    model = Book
```

**34. Configure Date Picker Widget**

```python
# admin.py
class AuthorAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.DateField: {'widget': django_filters.DateFilter(widget=DateWidget(attrs={'placeholder': 'Date Select'}))}
    }
```

**35. Configure Select2 Widget**

```python
# settings.py
JET_SELECT2_THEME = "bootstrap4"
JET_SELECT2_CSS = "

<div data-gb-custom-block data-tag="static" data-0='jet/css/select2.css'></div>"
JET_SELECT2_JS = "<div data-gb-custom-block data-tag="static" data-0='jet/js/select2.full.js'></div>"
```

**36. Use Jet Request Middleware**

```python
# settings.py
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'jet.middleware.ThreadLocalMiddleware',  # Jet middleware
]
```
