Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vilkoz opened this issue Mar 1, 2023 · 1 comment

Comments

@vilkoz
Copy link
Contributor

vilkoz commented Mar 1, 2023

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 added a commit that referenced this issue Mar 1, 2023
Fixes issue #17 : TabularInline and StackedInline add/delete buttons don't work
@app-generator
Copy link
Owner

Fix tagged and shipped in v1.0.10

TY @vilkoz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants