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
The URL is absolute, since it starts with a slash. Maybe this helps you:
Look at request.build_absolute_uri() (http/__init__.py)
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Yes, but i can't get the request object in the model :( So this is not a solution :(