Inline edit of django ForeignKey and proxy models

624 views Asked by At

I get an 404 error when I try to edit inline (in a popup) an object referenced by a ForeignKey to a proxy model in the admin part (using django suite) of my application.

My base model and the proxy model:

class Book(MyBase):
    """
    Base book model
    """
    # [...]

class SpecialBook(Book):
    """ 
    Need to leave this separated as a proxy model.
    """
    class Meta:
        proxy = True

My model to bind books with it's genre. The book field can hold references to both Book and SpecialBook, via documentation:

[proxy] class operates on the same database table as it's parent

class BookGenre(MyBase):
    """
    bind books with it's genre
    """

    book = models.ForeignKey(Book)
    genre = models.ForeignKey(Genre)

The admin.py stuff to manage the genres:

class BookGenreInline(suit.admin.SortableTabularInline):
    model = BookGenre

    # [...]


@admin.register(Genre)
class GenreAdmin(AdminBase):
    inlines = [
        BookGenreInline,
        # [...],
    ]
    fields = [...]

The above generates me an admin page with a select field with the existing Book (and SpecialBook) objects. On the right to the select I've got the "Change selected" and "Add another" buttons (template imported from here I believe). The only problem is that the edit option works only when a Book object is selected, doesn't work for SpecialBook. As far as I can see it's connected with the fact that the change_related_template_url found here isn't updated. The url for editing Book objects looks like /admin/books/book/ID[...] and works correctly, but doesn't change to /admin/books/specialbook/ID[...] when I select the SpecialBook object.

Can anybody suggest an elegant fix here?

0

There are 0 answers