Take a look at https://github.com/tkaemming/django-orderable. i've used it several times.
On Saturday, December 1, 2012 3:24:49 AM UTC-6, Andrew Brown wrote: > > Greetings, > > I'm hopeful someone can point me in the right direction to improve the > admin UI for my app. I need to allow for the creation and display of an > ordered list of books. I had no problem setting this up and editing the > lists in the admin UI, but the UX for an admin leaves much to be desired. > > The two biggest issues are that books can be saved to the same position as > books already on a list, and the admin always has to specify a position on > the list for each book (rather than simply adding the most recent book to > the end). Ideally books could even be dragged around and visually > reordered. This is a pretty classic ordered-list scenario, so I'm hoping > someone has already done some work to improve the admin UI for this case. > Is anyone aware of anything that might help? > > The code I'm using in my app is below- it is dead simple and pretty much > straight from the documentation. I have created two models for this > purpose- Book and List, which are associated by a ListMember class using a > through relationship. > > class Book(models.Model): > > title = models.CharField(max_length=200) > > class List(models.Model): > > books = models.ManyToManyField(Book, through="ListMember") > > class ListMember(models.Model): > > list = models.ForeignKey(List) > book = models.ForeignKey(Book) > position = models.IntegerField() > > > Then in my admin code I've created BookAdmin, ListAdmin, and > ListMemberInline. I've also included simplified code for these classes > below. > > class ListMemberInline(admin.TabularInline): > > model = List.books.through > > class ListAdmin(admin.ModelAdmin): > > inlines = ['ListMemberInline',] > excludes = ('books',) > > class BookAdmin(admin.ModelAdmin): > > inlines = ['ListMemberInline',] > > If anyone is aware of improvements to the admin UI for this case that I > could reuse I would really appreciate a pointer in the right direction. > Alternatively, guidance on how to improve this myself would also be very > helpful. > > Thanks! > Andrew > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/r_wZD1Jz_9sJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.