通过拖动对django的内联模型管理员重新排序
django-orderable-inlines的Python项目详细描述
拖动此形状可对django的内联模型管理员重新排序
安装
pip install django-orderable-inlines
将orderable_inlines添加到INSTALLED_APPS中。
示例
models.py:
from django.db import models class Gallery(models.Model): name = models.CharField(max_length=16) class Photo(models.Model): gallery = models.ForeignKey(Gallery) image = models.ImageField(upload_to='gallery_photos') order = models.PositiveIntegerField(default=1)
admin.py:
from django.contrib import admin from gallery.models import Gallery, Photo from orderable_inlines import OrderableTabularInline class PhotoInline(OrderableTabularInline): model = Book orderable_field = 'order' class GalleryAdmin(admin.ModelAdmin): inlines = [ PhotoInline, ] admin.site.register(Gallery, GalleryAdmin)