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:
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
After adding block extrahead to layouts/base.html the above error is fixed, but new error appear:
It seems that background urls for inline-detelink and ...addlink are wrong in widgets.css and forms.css:
Example application
books
: models.py:admin.py:
When trying to create new book with multiple authors there are no add-inline and delete-inline buttons:
prepopulate.js has the following problem
In django admin the
django.jQuery
orwindow.django.jQuery
variable is declared insidejquery.init.js
which is included inadmin/base.html
in block{% block extrahead %}{% endblock %}
But thelayouts/base.html
of this app doesn't have blockblock extrahead
After adding
block extrahead
tolayouts/base.html
the above error is fixed, but new error appear:It seems that background urls for
inline-detelink
and...addlink
are wrong inwidgets.css
andforms.css
: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
andicon-addlink.svg
from../img
to../admin/img
the problem is fixed:Conclusion
block extrahead
should be inlayouts/base.html
../admin/img/
instead of../img/
Will provide pull request soon