Wednesday, June 30, 2010

Re: "View on Site" for instance with Many-To-Many relation to the Site model

tl;dr version:

admin "view on site" link returns the first Site associated with a
model, rather than the current Site. Is this correct? It seems that it
should return the current site (if it is picking one arbitrarily)

-Sam

On Jun 29, 11:19 pm, Sam <sam.vev...@gmail.com> wrote:
> Hello,
>
> I'm using a model with a many to many relationship toSite. I noticed
> that the redirect from the adminsite(the link "ViewonSite") is to
> a domain that is not associated with the current SITE_ID. in other
> words I have two sites, "devel.domain.com" and "www.domain.com." When
> I select "ViewonSite" when using the admin on thewww.domain.comsite, it sends me to the resource on the devel.domain.com instead.
>
> Inspecting the admin code, I see the url conf for redirects on line
> 227 in
> django/contrib/admin/sites.py
>
> Tracing the code backwards I eventually get to
> django.contrib.contenttypes.views.shortcut, theviewthat performs the
> redirect. I see in thatview, the model instance we are trying to
> "ViewonSite" is inspected to determine if it has a relation (Many-to-
> Many or Many-To-One) to theSitemodel.
>
> starting on line 32 in django/contrib/contenttypes/views.py we see
> this chunk of code dealing with the Many To Many:
> *snip*
>
>     # First, look for an many-to-many relationship toSite.
>     for field in opts.many_to_many:
>         if field.rel.to isSite:
>             try:
>                 # Caveat: In the case of multiple related Sites, this
> just
>                 # selects the *first* one, which is arbitrary.
>                 object_domain = getattr(obj, field.name).all()
> [0].domain
>             except IndexError:
>                 pass
>             if object_domain is not None:
>                 break
>
> *endsnip*
>
> What this code is doing is attempting to find a domain to concatenate
> with the result of `get_absolute_url()`
>
> My question is, why do we a arbitrarily select the firstSiteinstance
> in the many to many relationship? Wouldn't it make sense to pick theSiteinstance associated with the running SITE_ID? The reason I ask
> this is that it is confusing for the admin to redirect away from the
> runningsite, to anothersite.
>
> I believe this to be a question of correctness. Rather than choosing,
> arbitrarily, a randomsiteto redirect to, why not redirect, again
> arbitrarily, to the currentsite? Anyways, I would appreciate any
> feedback on this, it has come up and I am at a loss to explain this
> behavior in the admin. Am I missing something?
>
> Thanks much,
> Sam

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment