Re: Problem with get_absolute_url() in admin

2018-06-11 Thread Joakim Hove
Thank you;

my main problem was with the sites model - and the default value for
SITE_ID == 1. I had no intention of hardcoding the URL.

On Mon, Jun 11, 2018 at 12:58 AM Anthony Anonde  wrote:

> the example.com is am example django give for Site. Which means there is
> a way for you to manage more than one site at a time, basically using the
> site_id.
> To you Questions, i don't understand why you want to hard code your uri
> routing like that when you can easily use the app_name and name convention
> which is more dynamic then hard coding it like that:
> for example at the model Transaction urls.py
> app_name = "trans"
> url(r'(?P-/d+)$', views.func, name='account_trans'),
>
> def get_absolute_url(self):
> return reverse("trans:account_trans",  kwargs={"pk":self.pk})
>
>
> and you will be just fine hope this help
>
>
>
> On Sunday, June 10, 2018 at 12:30:51 PM UTC+1, Joakim Hove wrote:
>>
>> Hello,
>>
>> I have a model `Transaction` which can be viewed at the url:
>> /transaction/view/$ID/ - if I just enter that url in the browser, or in
>> template everything works. But when I have the following get_abolute_url()
>> method:
>>
>> def get_absolute_url(self):
>>  return "/transaction/view/{}/".format( self.id )
>>
>> things do not work from the Admin. When I click on the "View on Site"
>> link i am redirected to "http://example.com/transaction/view/23635/"; and
>> I get an error message about failed XML parsing. I have no clue where the "
>> example.com" address comes from - that string is not in my codebase. If
>> I hardcode the get_absolute_url to:
>>
>> def get_absolute_url(self):
>>  return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)
>>
>> That works in development, but needless to say that is not a very good
>> approach.
>>
>> I am on Django 1.10
>>
>>
>> Regard Joakim
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5678b297-2693-4ae8-b249-08e42713ebf7%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M_diEj6K9Mw7kPAvrjWs6JUjE1H0-zgB-0M8VFKSDVq%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Anthony Anonde
the example.com is am example django give for Site. Which means there is a 
way for you to manage more than one site at a time, basically using the 
site_id.
To you Questions, i don't understand why you want to hard code your uri 
routing like that when you can easily use the app_name and name convention 
which is more dynamic then hard coding it like that: 
for example at the model Transaction urls.py 
app_name = "trans"
url(r'(?P-/d+)$', views.func, name='account_trans'),

def get_absolute_url(self):
return reverse("trans:account_trans",  kwargs={"pk":self.pk})


and you will be just fine hope this help



On Sunday, June 10, 2018 at 12:30:51 PM UTC+1, Joakim Hove wrote:
>
> Hello,
>
> I have a model `Transaction` which can be viewed at the url: 
> /transaction/view/$ID/ - if I just enter that url in the browser, or in 
> template everything works. But when I have the following get_abolute_url() 
> method:
>
> def get_absolute_url(self):
>  return "/transaction/view/{}/".format( self.id )
>
> things do not work from the Admin. When I click on the "View on Site" link 
> i am redirected to "http://example.com/transaction/view/23635/"; and I get 
> an error message about failed XML parsing. I have no clue where the "
> example.com" address comes from - that string is not in my codebase. If I 
> hardcode the get_absolute_url to:
>
> def get_absolute_url(self):
>  return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)
>
> That works in development, but needless to say that is not a very good 
> approach.
>
> I am on Django 1.10
>
>
> Regard Joakim
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5678b297-2693-4ae8-b249-08e42713ebf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Thank you;

that was indeed it!

On Sunday, June 10, 2018 at 11:03:54 PM UTC+2, Melvyn Sopacua wrote:
>
> On zondag 10 juni 2018 22:54:10 CEST Joakim Hove wrote: 
> > > > It is the default hostname for django.contrib.sites 
> > > 
> > > <
> https://github.com/django/django/blob/master/django/contrib/sites/managem 
> > > ent.py#L28> with SITE_ID = 1. 
> > 
> > OK - so that might be a smoking gun that I have not configured the 
> "sites" 
> > model correctly? I have so far not really related to the "sites" 
> > functionality at all. 
>
> It's enabled by default. And from the admin you can edit that hostname and 
> add 
> more sites. 
> Because Django supports multiple sites with a single admin, it generates 
> fully 
> qualified URLs for the "view on site" functionality, if 
> django.contrib.sites is 
> in INSTALLED_APPS. 
>
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/af654af4-ff87-45bd-9da4-038cbefc09cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Melvyn Sopacua
On zondag 10 juni 2018 22:54:10 CEST Joakim Hove wrote:
> > > It is the default hostname for django.contrib.sites
> > 
> >  > ent.py#L28> with SITE_ID = 1.
> 
> OK - so that might be a smoking gun that I have not configured the "sites"
> model correctly? I have so far not really related to the "sites"
> functionality at all.

It's enabled by default. And from the admin you can edit that hostname and add 
more sites.
Because Django supports multiple sites with a single admin, it generates fully 
qualified URLs for the "view on site" functionality, if django.contrib.sites is 
in INSTALLED_APPS.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1591437.ilrU06Q2TX%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove

>
>   
>
> > It is the default hostname for django.contrib.sites 
> 
>  
> with SITE_ID = 1.
>
>
OK - so that might be a smoking gun that I have not configured the "sites" 
model correctly? I have so far not really related to the "sites" 
functionality at all. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dee9819f-fb1d-4a2f-9449-89ec0b3a8370%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Melvyn Sopacua
On zondag 10 juni 2018 13:30:51 CEST Joakim Hove wrote:

> things do not work from the Admin. When I click on the "View on Site" link
> i am redirected to "http://example.com/transaction/view/23635/"; and I get
> an error message about failed XML parsing. I have no clue where the
> "example.com" address comes from - that string is not in my codebase.

It is the default hostname for django.contrib.sites[1] with SITE_ID = 1.
-- 
Melvyn Sopacua


[1] https://github.com/django/django/blob/master/django/contrib/sites/
management.py#L28

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2721239.SktWtCEFV2%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Thank  you for answering;

but I do not agree fully with your answer:

1. It is the @permalink decorator which is removed from Django 2.x - not
the get_abolute_url() method.
2. I agree using the reverse in the get_absolute_url() is nicer, and I have
also tried that - but the ersults were the same ... ;-(
3. Yes - I should upgrade

On Sun, Jun 10, 2018 at 2:19 PM Gerald Brown  wrote:

>  In version 2 of Django that function has been removed.
>
> For v 1.10 here is a link that might help:
> https://docs.djangoproject.com/en/1.10/ref/models/instances/#get-absolute-url
>
> Here is another link that might be of help:
> https://stackoverflow.com/questions/13503645/what-is-permalink-and-get-absolute-url-in-django?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
>
> Hope this helps.
>
> BTW the first link says V1.10 is obsolete and is no longer supported!!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1c0b4b32-7154-4dd4-b437-92d0bba6c70e%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALKD1M8HqPs9rijWh63bAThh-o-6EsLNYFWLGQBm4%2BXjqkbB2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with get_absolute_url() in admin

2018-06-10 Thread Gerald Brown
 In version 2 of Django that function has been removed.

For v 1.10 here is a link that might help: 
https://docs.djangoproject.com/en/1.10/ref/models/instances/#get-absolute-url

Here is another link that might be of help: 
https://stackoverflow.com/questions/13503645/what-is-permalink-and-get-absolute-url-in-django?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Hope this helps.

BTW the first link says V1.10 is obsolete and is no longer supported!!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1c0b4b32-7154-4dd4-b437-92d0bba6c70e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with get_absolute_url() in admin

2018-06-10 Thread Joakim Hove
Hello,

I have a model `Transaction` which can be viewed at the url: 
/transaction/view/$ID/ - if I just enter that url in the browser, or in 
template everything works. But when I have the following get_abolute_url() 
method:

def get_absolute_url(self):
 return "/transaction/view/{}/".format( self.id )

things do not work from the Admin. When I click on the "View on Site" link 
i am redirected to "http://example.com/transaction/view/23635/"; and I get 
an error message about failed XML parsing. I have no clue where the 
"example.com" address comes from - that string is not in my codebase. If I 
hardcode the get_absolute_url to:

def get_absolute_url(self):
 return "http://127.0.0.1:8000/transaction/view{}/".format(self.id)

That works in development, but needless to say that is not a very good 
approach.

I am on Django 1.10


Regard Joakim


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6e8b55d-56b5-40f4-8505-76f1447c1542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.