views:

63

answers:

1

I have flatpage attached to multiple sites. Its admin preview chooses arbitrary site, which is quite obvious after debugging up to lines 35-36 of django.contrib.contenttypes.views.shortcut().

What would be the best way of fixing this problem?

I see that the shortcut() function takes a request object, so I could just extract host from there, but I prefer to not patch the live server.

I haven't looked at catching admin url yet, so maybe someone can suggest some nice solution?

+1  A: 

In my opinion, this could be considered a bug in Django, and at least a partial fix would be to check if the current SITE_ID is one of the sites related to the object, and if so use that one instead of an arbitrary one. You could file a ticket with a patch.

To fix it without patching Django, you might look into overriding the admin edit-form template for the flatpages model so that you can put the URL you want into that link instead of the default one that goes to the shortcut view. I haven't looked into it enough to know how clean that would be.

Another option might be to monkeypatch the Flatpage model with a get_absolute_url method that actually returns a complete absolute url, including the domain, based on Site.objects.get_current().domain.

Carl Meyer
Ok, thank you, I thought that maybe I'm overlooking some quick fix.
Tomasz Zielinski