app-generator / django-admin-volt

Django Admin Volt - Free template for Django Admin Interface | AppSeed
https://pypi.org/project/django-admin-volt/
MIT License
140 stars 33 forks source link

TabularInline, StackedInline add and delete buttons don't work [Have solution] #17

Closed vilkoz closed 1 year ago

vilkoz commented 1 year ago

Example application books: models.py:

from django.db import models

# Create your models here.

class Book(models.Model):
    name = models.CharField(max_length=255, null=False)

class Author(models.Model):
    name = models.CharField(max_length=255, null=False)
    author = models.ForeignKey(Book, related_name="books", on_delete=models.CASCADE)

admin.py:

from django.contrib import admin

from .models import Author, Book

# Register your models here.
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
    pass

class AuthorInline(admin.TabularInline):
    model = Author

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    inlines = [AuthorInline]

When trying to create new book with multiple authors there are no add-inline and delete-inline buttons:

screnshot

prepopulate.js has the following problem

'use strict';
{
    const $ = django.jQuery; //here

In django admin the django.jQuery or window.django.jQuery variable is declared inside jquery.init.js which is included in admin/base.html in block {% block extrahead %}{% endblock %} But the layouts/base.html of this app doesn't have block block extrahead screen

After adding block extrahead to layouts/base.html the above error is fixed, but new error appear:

urls

It seems that background urls for inline-detelink and ...addlink are wrong in widgets.css and forms.css:

.inline-deletelink {
    float: right;
    text-indent: -9999px;
    background: url(../img/inline-delete.svg) 0 0 no-repeat;
    width: 16px;
    height: 16px;
    border: 0px none;
}

They lead to /static/img/inline-delete.svg but image is located in /static/admin/img/inline-delete.svg

When changed urls for inline-delete.svg and icon-addlink.svg from ../img to ../admin/img the problem is fixed:

image

Conclusion

  1. block extrahead should be in layouts/base.html
  2. all background image urls in css files should be from ../admin/img/ instead of ../img/

Will provide pull request soon

app-generator commented 1 year ago

Fix tagged and shipped in v1.0.10

TY @vilkoz