With get_absolute_url() [1] we can build a URL of a model entry. The Problem 
is, 
this is not really a _complete_ URL. The protocol and domain is absent.

I implemented this:

-------------------------------------------------------------------------------
     def get_absolute_uri(self):
         """
         returned the complete absolute URI (with the domain/host part)
         """
         url = self.get_absolute_url()

         if os.environ.get("HTTPS") == "on":
             protocol = "https"
         else:
             protocol = "http"

         domain = os.environ.get("SERVER_NAME")
         if not domain:
             domain = os.environ.get("HTTP_HOST")
         if not domain:
             # Can't build the complete uri without the domain ;(
             # e.g. running the django development server
             return url

         return "%s://%s%s" % (protocol, domain, url)
-------------------------------------------------------------------------------

I think it's not a good idea to get information from os.environ. This only 
works 
with Apache.
The better way is to use request.META or directly request.build_absolute_uri(). 
But IMHO i can't get the request object in the model.

I can't use Site.objects.get_current().domain [2], because i didn't use the 
Site 
framework. And this is not a good idea: The protocoll is always "http".

Any better idea?

[1] <http://www.djangoproject.com/documentation/model-api/#get-absolute-url>
[2] 
<http://www.djangoproject.com/documentation/sites/#getting-the-current-domain-for-full-urls>


-- 
Mfg.

Jens Diemer


----
A django powered CMS: http://www.pylucid.org


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to