[Django]-Django ordered ManyToManyField in admin interface


This is quick and a bit rough, but it should get you close(r).

from django.db import models
from django.contrib import admin

class Document(models.Model):
    name = models.CharField(max_length = 128)

    def __unicode__(self):
        return self.name

class Author(models.Model):
    name = models.CharField(max_length = 128)
    document = models.ManyToManyField(Document, through = 'Foo')

    def __unicode__(self):
        return self.name

class Foo(models.Model):
    document = models.ForeignKey(Document)
    author = models.ForeignKey(Author)
    author_order = models.IntegerField()

class FooInline(admin.TabularInline):
    model = Foo

class DocumentAdmin(admin.ModelAdmin):
    inlines = [ FooInline ]

admin.site.register(Document, DocumentAdmin)



this might help you too – there is some utility in Django to build models for the legacy databases.

I’ve built a model for mediawiki database using it. It gets most of the things right, but you’ll need to tweak the models a little.


Leave a comment