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

Fixed sortable widget not working in stacked inline admin #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion example/testapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from example.testapp.models import Car, ParkingArea
from example.testapp.models import Car, Garage, ParkingArea


class ParkingAreaAdmin(admin.ModelAdmin):
Expand All @@ -15,5 +15,15 @@ class ParkingAreaAdmin(admin.ModelAdmin):
)


class ParkingAreaInlineAdmin(admin.StackedInline):
model = ParkingArea
extra = 0


class GarageAdmin(admin.ModelAdmin):
inlines = [ParkingAreaInlineAdmin]


admin.site.register(Car)
admin.site.register(Garage, GarageAdmin)
admin.site.register(ParkingArea, ParkingAreaAdmin)
5 changes: 5 additions & 0 deletions example/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ def __str__(self):
return str(self.car) + " in " + str(self.parkingarea) # pylint: disable=no-member


class Garage(models.Model):
name = models.CharField(max_length=30)


class ParkingArea(models.Model):
name = models.CharField(max_length=50)
garage = models.ForeignKey(Garage, on_delete=models.CASCADE, null=True, blank=True, default=None)
cars = SortedManyToManyField(Car, base_class=BaseCarThrough)

def __str__(self):
Expand Down
4 changes: 3 additions & 1 deletion sortedm2m/static/sortedm2m/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ if (typeof jQuery === 'undefined') {
}

function iterateUl() {
$('.sortedm2m-items').each(function () {
// Add sortable only to visible .sortedm2m-items.
// Exclude element with class .sortedm2m since they are already initialized
$('.sortedm2m-items:visible:not(.sortedm2m)').each(function () {
var ul = $(this);

prepareUl(ul);
Expand Down
Loading