Re: Change the url

2009-01-09 Thread Briel
 django is both
> > writing and running get_absolute_url for you.
>
> > Another plus when using named urls, is that you can give your urls
> > name that give meaning. That will make it a lot easier to understand
> > what's going on in the template when you read your own code 6 months
> > from now. Especially if you have several views of one model.
>
> > Say you had a model for blog posts.
> > Then you might want to have an url for your own blogs, another one for
> > your friend's blogs ect. You could still use get_absolute_url, but
> > this time, it would be harder to make and use, as you now would need
> > to know what url to get. Also when reading the template it would be
> > hard to see which url is being displayed. Instead using tags like
> > {% url friends_blog args=x %}
> > {% url your_blog args=x %}
> > {% url all_blog args=x %}
> > would be easy to understand after not working with the code for a long
> > time.
>
> > -Briel
>
> > Praveen wrote:
> > > Hi Briel i am totally confused now.
> > > My senior told me to write get_absolute_url
>
> > > so i wrote get_absolute_url like this
> > > class Listing_channels(models.Model):
> > >     list_channel = models.CharField(max_length = 20)
> > >     visibility = models.BooleanField()
>
> > >     def __unicode__(self):
> > >         return self.list_channel
>
> > >     def get_absolute_url(self):
> > >            return u'/category/listing_view/%i/' % self.id
>
> > > and in html template i am calling
>
> > > {%if listing_result %}
> > >     {% for n in listing_result %}
> > >          {{n.list_channel}} > > li>
> > >     {% endfor %}
> > > {% else %}
> > >     not available
> > > {% endif %}
> > > 
>
> > > so its working fine.
>
> > > so now i have two mechanism one is your as you told me to write and
> > > second one is
> > > get_absolute_url() function.
>
> > > Now my confusion is if we have another same class event_channel and
> > > event and many more classes like this then i will have to write
> > > get_absolute_url() for each class
> > > and if go with you then there i need to change only in urls.py that i
> > > think fine.
>
> > > so i should go with get_absolute_url? give me the best and solid
> > > reason so i could make understand to senior, and you know the senior
> > > behave..
>
> > > Briel wrote:
>
> > > > Using urls with names will solve your problem.
>
> > > > Basically if you change your urls.py like this:
>
> > > >     url(
> > > >         r'^category/listing_view/(?P\w+)/$',
> > > >        'mysite.library.views.listing_view',
> > > >        name = 'name_for_this_view'
> > > >     ),
>
> > > > What I have done is to add a name to the url for convenience I also
> > > > used the url() function. This name can now be used instead of the link
> > > > to your view. So if you were to change the site structure, when
> > > > changes would be made to your urlconf, django would then be able to
> > > > figure things out for you. In this version your new link would look
> > > > like this:
>
> > > > {{n.list_channel}}
>
> > > > In the docs you can read about it at
> > > > url():http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > > > naming:http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> > > > Good luck.
> > > > -Briel
>
> > > > On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> > > > > Hi Malcolm i am very new bie of Django. i read through
> > > > > get_absolute_url but do not know how to use.
> > > > > What you have given the answer i tried with that and its working fine
> > > > > but my senior asked me what will happen if i change the site name then
> > > > > every where you will have to change url
> > > > > mysite.library.views.listing_view.
>
> > > > > so they told me to use get_absolute_url
>
> > > > > i wrote get_absolute_ul in models.py
> > > > > def get_absolute_url(self):
> > > > > return "/listing/%i/" % self.id
> > > > > and i am trying to use in my html page template but i don't know how
> > > > > to use
>
> > > > >  {{n.list_channel}} > > > > li>
>
>

Re: Change the url

2009-01-09 Thread Praveen
solute_url like this
> > class Listing_channels(models.Model):
> >     list_channel = models.CharField(max_length = 20)
> >     visibility = models.BooleanField()
>
> >     def __unicode__(self):
> >         return self.list_channel
>
> >     def get_absolute_url(self):
> >            return u'/category/listing_view/%i/' % self.id
>
> > and in html template i am calling
>
> > {%if listing_result %}
> >     {% for n in listing_result %}
> >          {{n.list_channel}} > li>
> >     {% endfor %}
> > {% else %}
> >     not available
> > {% endif %}
> > 
>
> > so its working fine.
>
> > so now i have two mechanism one is your as you told me to write and
> > second one is
> > get_absolute_url() function.
>
> > Now my confusion is if we have another same class event_channel and
> > event and many more classes like this then i will have to write
> > get_absolute_url() for each class
> > and if go with you then there i need to change only in urls.py that i
> > think fine.
>
> > so i should go with get_absolute_url? give me the best and solid
> > reason so i could make understand to senior, and you know the senior
> > behave..
>
> > Briel wrote:
>
> > > Using urls with names will solve your problem.
>
> > > Basically if you change your urls.py like this:
>
> > >     url(
> > >         r'^category/listing_view/(?P\w+)/$',
> > >        'mysite.library.views.listing_view',
> > >        name = 'name_for_this_view'
> > >     ),
>
> > > What I have done is to add a name to the url for convenience I also
> > > used the url() function. This name can now be used instead of the link
> > > to your view. So if you were to change the site structure, when
> > > changes would be made to your urlconf, django would then be able to
> > > figure things out for you. In this version your new link would look
> > > like this:
>
> > > {{n.list_channel}}
>
> > > In the docs you can read about it at
> > > url():http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > > naming:http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> > > Good luck.
> > > -Briel
>
> > > On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> > > > Hi Malcolm i am very new bie of Django. i read through
> > > > get_absolute_url but do not know how to use.
> > > > What you have given the answer i tried with that and its working fine
> > > > but my senior asked me what will happen if i change the site name then
> > > > every where you will have to change url
> > > > mysite.library.views.listing_view.
>
> > > > so they told me to use get_absolute_url
>
> > > > i wrote get_absolute_ul in models.py
> > > > def get_absolute_url(self):
> > > > return "/listing/%i/" % self.id
> > > > and i am trying to use in my html page template but i don't know how
> > > > to use
>
> > > >  {{n.list_channel}} > > > li>
>
> > > > then again same problem. first time when some one click on link it
> > > > works fine but second time it appends the link 
> > > > likehttp://127.0.0.1:8000/category/listing_view/3/3
>
> > > > Please give me some idea
>
> > > > On Jan 8, 3:37 pm, Praveen <praveen.python.pl...@gmail.com> wrote:
>
> > > > > Thank you so much Malcolm.
> > > > > every one gives only the link and tell to read but your style of
> > > > > solving the problem is amazing. how you explained me in a nice way
> > > > > that i can never ever find in djangoproject.com.
> > > > > Thanks you so much malcom
>
> > > > > On Jan 8, 3:23 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> > > > > wrote:
>
> > > > > > I'm going to trim your code to what looks like the relevant portion 
> > > > > > of
> > > > > > the HTML template, since that's where the easiest solution lies.
>
> > > > > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > > > > > [...]
>
> > > > > > > list_listing.html
>
> > > > > > > 
> > > > > > > Sight Seeings
> > > > > > > 
> > > > > > > {%if listing_result %}
> > > > > > > {% for n in listing_result %}
> > > > > > > {{n.

Re: Change the url

2009-01-08 Thread Praveen

Thank you so much Briel. Really you gave me a nice explanation and the
same think i was thinking but was not able to make understand to my
senior. let me put your idea to my senior and lets see what they say..
but really i appreciate you and for your politeness.

On Jan 8, 6:43 pm, Briel <toppe...@gmail.com> wrote:
> Hi Praveen
> I personally would prefer naming the urls rather than using the
> get_absolute_url.
> Both can accomplish your goal, but naming the urls is a more robust
> and in other ways a better solution.
>
> If you in a week decide that the url should not be /category/... but
> instead /whatever/... you would have to recode your get_absolute_url
> method. However, if you use the names in urls, everything would still
> work after changing the urls. The reason is that when using the name
> of an url, Django will find what the absolute url will be given the
> args you use, in your example the id.
> In a way, you could say that when using named urls, django is both
> writing and running get_absolute_url for you.
>
> Another plus when using named urls, is that you can give your urls
> name that give meaning. That will make it a lot easier to understand
> what's going on in the template when you read your own code 6 months
> from now. Especially if you have several views of one model.
>
> Say you had a model for blog posts.
> Then you might want to have an url for your own blogs, another one for
> your friend's blogs ect. You could still use get_absolute_url, but
> this time, it would be harder to make and use, as you now would need
> to know what url to get. Also when reading the template it would be
> hard to see which url is being displayed. Instead using tags like
> {% url friends_blog args=x %}
> {% url your_blog args=x %}
> {% url all_blog args=x %}
> would be easy to understand after not working with the code for a long
> time.
>
> -Briel
>
>
>
> Praveen wrote:
> > Hi Briel i am totally confused now.
> > My senior told me to write get_absolute_url
>
> > so i wrote get_absolute_url like this
> > class Listing_channels(models.Model):
> >     list_channel = models.CharField(max_length = 20)
> >     visibility = models.BooleanField()
>
> >     def __unicode__(self):
> >         return self.list_channel
>
> >     def get_absolute_url(self):
> >            return u'/category/listing_view/%i/' % self.id
>
> > and in html template i am calling
>
> > {%if listing_result %}
> >     {% for n in listing_result %}
> >          {{n.list_channel}} > li>
> >     {% endfor %}
> > {% else %}
> >     not available
> > {% endif %}
> > 
>
> > so its working fine.
>
> > so now i have two mechanism one is your as you told me to write and
> > second one is
> > get_absolute_url() function.
>
> > Now my confusion is if we have another same class event_channel and
> > event and many more classes like this then i will have to write
> > get_absolute_url() for each class
> > and if go with you then there i need to change only in urls.py that i
> > think fine.
>
> > so i should go with get_absolute_url? give me the best and solid
> > reason so i could make understand to senior, and you know the senior
> > behave..
>
> > Briel wrote:
>
> > > Using urls with names will solve your problem.
>
> > > Basically if you change your urls.py like this:
>
> > >     url(
> > >         r'^category/listing_view/(?P\w+)/$',
> > >        'mysite.library.views.listing_view',
> > >        name = 'name_for_this_view'
> > >     ),
>
> > > What I have done is to add a name to the url for convenience I also
> > > used the url() function. This name can now be used instead of the link
> > > to your view. So if you were to change the site structure, when
> > > changes would be made to your urlconf, django would then be able to
> > > figure things out for you. In this version your new link would look
> > > like this:
>
> > > {{n.list_channel}}
>
> > > In the docs you can read about it at
> > > url():http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > > naming:http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> > > Good luck.
> > > -Briel
>
> > > On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> > > > Hi Malcolm i am very new bie of Django. i read through
> > > > get_absolute_url but do not know how to use.
> > > > What you have given the answer i tried with that and its working fine
> > > > but my senior

Re: Change the url

2009-01-08 Thread Briel

Hi Praveen
I personally would prefer naming the urls rather than using the
get_absolute_url.
Both can accomplish your goal, but naming the urls is a more robust
and in other ways a better solution.

If you in a week decide that the url should not be /category/... but
instead /whatever/... you would have to recode your get_absolute_url
method. However, if you use the names in urls, everything would still
work after changing the urls. The reason is that when using the name
of an url, Django will find what the absolute url will be given the
args you use, in your example the id.
In a way, you could say that when using named urls, django is both
writing and running get_absolute_url for you.

Another plus when using named urls, is that you can give your urls
name that give meaning. That will make it a lot easier to understand
what's going on in the template when you read your own code 6 months
from now. Especially if you have several views of one model.

Say you had a model for blog posts.
Then you might want to have an url for your own blogs, another one for
your friend's blogs ect. You could still use get_absolute_url, but
this time, it would be harder to make and use, as you now would need
to know what url to get. Also when reading the template it would be
hard to see which url is being displayed. Instead using tags like
{% url friends_blog args=x %}
{% url your_blog args=x %}
{% url all_blog args=x %}
would be easy to understand after not working with the code for a long
time.

-Briel

Praveen wrote:
> Hi Briel i am totally confused now.
> My senior told me to write get_absolute_url
>
> so i wrote get_absolute_url like this
> class Listing_channels(models.Model):
> list_channel = models.CharField(max_length = 20)
> visibility = models.BooleanField()
>
> def __unicode__(self):
> return self.list_channel
>
> def get_absolute_url(self):
>   return u'/category/listing_view/%i/' % self.id
>
> and in html template i am calling
>
> {%if listing_result %}
> {% for n in listing_result %}
>  {{n.list_channel}} li>
> {% endfor %}
> {% else %}
> not available
> {% endif %}
> 
>
> so its working fine.
>
> so now i have two mechanism one is your as you told me to write and
> second one is
> get_absolute_url() function.
>
> Now my confusion is if we have another same class event_channel and
> event and many more classes like this then i will have to write
> get_absolute_url() for each class
> and if go with you then there i need to change only in urls.py that i
> think fine.
>
> so i should go with get_absolute_url? give me the best and solid
> reason so i could make understand to senior, and you know the senior
> behave..
>
>
> Briel wrote:
>
> > Using urls with names will solve your problem.
> >
> > Basically if you change your urls.py like this:
> >
> > url(
> > r'^category/listing_view/(?P\w+)/$',
> >'mysite.library.views.listing_view',
> >name = 'name_for_this_view'
> > ),
> >
> > What I have done is to add a name to the url for convenience I also
> > used the url() function. This name can now be used instead of the link
> > to your view. So if you were to change the site structure, when
> > changes would be made to your urlconf, django would then be able to
> > figure things out for you. In this version your new link would look
> > like this:
> >
> > {{n.list_channel}}
> >
> >
> > In the docs you can read about it at
> > url(): http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > naming: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
> >
> > Good luck.
> > -Briel
> >
> > On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> > > Hi Malcolm i am very new bie of Django. i read through
> > > get_absolute_url but do not know how to use.
> > > What you have given the answer i tried with that and its working fine
> > > but my senior asked me what will happen if i change the site name then
> > > every where you will have to change url
> > > mysite.library.views.listing_view.
> > >
> > > so they told me to use get_absolute_url
> > >
> > > i wrote get_absolute_ul in models.py
> > > � � def get_absolute_url(self):
> > > � � � � return "/listing/%i/" % self.id
> > > and i am trying to use in my html page template but i don't know how
> > > to use
> > >
> > >  {{n.list_channel}} > > li>
> > >
> > > then again same problem. first time when some one click on link it
> > > works fine but second time it appends the link 
> &

Re: Change the url

2009-01-08 Thread Kip Parker

You can use reverse()  in your get_absolute_url method, it works the
same as the url template tag in using your url patterns to generate
the url.

http://docs.djangoproject.com/en/dev/topics/http/urls/?from=olddocs#reverse

On Jan 8, 12:58 pm, Praveen <praveen.python.pl...@gmail.com> wrote:
> Hi Briel i am totally confused now.
> My senior told me to write get_absolute_url
>
> so i wrote get_absolute_url like this
> class Listing_channels(models.Model):
>     list_channel = models.CharField(max_length = 20)
>     visibility = models.BooleanField()
>
>     def __unicode__(self):
>         return self.list_channel
>
>     def get_absolute_url(self):
>         return u'/category/listing_view/%i/' % self.id
>
> and in html template i am calling
>
> {%if listing_result %}
>     {% for n in listing_result %}
>          {{n.list_channel}} li>
>     {% endfor %}
> {% else %}
>     not available
> {% endif %}
> 
>
> so its working fine.
>
> so now i have two mechanism one is your as you told me to write and
> second one is
> get_absolute_url() function.
>
> Now my confusion is if we have another same class event_channel and
> event and many more classes like this then i will have to write
> get_absolute_url() for each class
> and if go with you then there i need to change only in urls.py that i
> think fine.
>
> so i should go with get_absolute_url? give me the best and solid
> reason so i could make understand to senior, and you know the senior
> behave..
>
> Briel wrote:
> > Using urls with names will solve your problem.
>
> > Basically if you change your urls.py like this:
>
> >     url(
> >         r'^category/listing_view/(?P\w+)/$',
> >        'mysite.library.views.listing_view',
> >        name = 'name_for_this_view'
> >     ),
>
> > What I have done is to add a name to the url for convenience I also
> > used the url() function. This name can now be used instead of the link
> > to your view. So if you were to change the site structure, when
> > changes would be made to your urlconf, django would then be able to
> > figure things out for you. In this version your new link would look
> > like this:
>
> > {{n.list_channel}}
>
> > In the docs you can read about it at
> > url():http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> > naming:http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> > Good luck.
> > -Briel
>
> > On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> > > Hi Malcolm i am very new bie of Django. i read through
> > > get_absolute_url but do not know how to use.
> > > What you have given the answer i tried with that and its working fine
> > > but my senior asked me what will happen if i change the site name then
> > > every where you will have to change url
> > > mysite.library.views.listing_view.
>
> > > so they told me to use get_absolute_url
>
> > > i wrote get_absolute_ul in models.py
> > > def get_absolute_url(self):
> > > return "/listing/%i/" % self.id
> > > and i am trying to use in my html page template but i don't know how
> > > to use
>
> > >  {{n.list_channel}} > > li>
>
> > > then again same problem. first time when some one click on link it
> > > works fine but second time it appends the link 
> > > likehttp://127.0.0.1:8000/category/listing_view/3/3
>
> > > Please give me some idea
>
> > > On Jan 8, 3:37 pm, Praveen <praveen.python.pl...@gmail.com> wrote:
>
> > > > Thank you so much Malcolm.
> > > > every one gives only the link and tell to read but your style of
> > > > solving the problem is amazing. how you explained me in a nice way
> > > > that i can never ever find in djangoproject.com.
> > > > Thanks you so much malcom
>
> > > > On Jan 8, 3:23 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> > > > wrote:
>
> > > > > I'm going to trim your code to what looks like the relevant portion of
> > > > > the HTML template, since that's where the easiest solution lies.
>
> > > > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > > > > [...]
>
> > > > > > list_listing.html
>
> > > > > > 
> > > > > > Sight Seeings
> > > > > > 
> > > > > > {%if listing_result %}
> > > > > > {% for n in listing_result %}
> > > > > > {{n.list_channel}}
> > > > > > {% endfo

Re: Change the url

2009-01-08 Thread Praveen

Hi Briel i am totally confused now.
My senior told me to write get_absolute_url

so i wrote get_absolute_url like this
class Listing_channels(models.Model):
list_channel = models.CharField(max_length = 20)
visibility = models.BooleanField()

def __unicode__(self):
return self.list_channel

def get_absolute_url(self):
return u'/category/listing_view/%i/' % self.id

and in html template i am calling

{%if listing_result %}
{% for n in listing_result %}
 {{n.list_channel}}
{% endfor %}
{% else %}
not available
{% endif %}


so its working fine.

so now i have two mechanism one is your as you told me to write and
second one is
get_absolute_url() function.

Now my confusion is if we have another same class event_channel and
event and many more classes like this then i will have to write
get_absolute_url() for each class
and if go with you then there i need to change only in urls.py that i
think fine.

so i should go with get_absolute_url? give me the best and solid
reason so i could make understand to senior, and you know the senior
behave..


Briel wrote:

> Using urls with names will solve your problem.
>
> Basically if you change your urls.py like this:
>
> url(
> r'^category/listing_view/(?P\w+)/$',
>'mysite.library.views.listing_view',
>name = 'name_for_this_view'
> ),
>
> What I have done is to add a name to the url for convenience I also
> used the url() function. This name can now be used instead of the link
> to your view. So if you were to change the site structure, when
> changes would be made to your urlconf, django would then be able to
> figure things out for you. In this version your new link would look
> like this:
>
> {{n.list_channel}}
>
>
> In the docs you can read about it at
> url(): http://docs.djangoproject.com/en/dev/topics/http/urls/#url
> naming: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2
>
> Good luck.
> -Briel
>
> On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> > Hi Malcolm i am very new bie of Django. i read through
> > get_absolute_url but do not know how to use.
> > What you have given the answer i tried with that and its working fine
> > but my senior asked me what will happen if i change the site name then
> > every where you will have to change url
> > mysite.library.views.listing_view.
> >
> > so they told me to use get_absolute_url
> >
> > i wrote get_absolute_ul in models.py
> > � � def get_absolute_url(self):
> > � � � � return "/listing/%i/" % self.id
> > and i am trying to use in my html page template but i don't know how
> > to use
> >
> >  {{n.list_channel}} > li>
> >
> > then again same problem. first time when some one click on link it
> > works fine but second time it appends the link 
> > likehttp://127.0.0.1:8000/category/listing_view/3/3
> >
> > Please give me some idea
> >
> > On Jan 8, 3:37�pm, Praveen <praveen.python.pl...@gmail.com> wrote:
> >
> > > Thank you so much Malcolm.
> > > every one gives only the link and tell to read but your style of
> > > solving the problem is amazing. how you explained me in a nice way
> > > that i can never ever find in djangoproject.com.
> > > Thanks you so much malcom
> >
> > > On Jan 8, 3:23�pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> > > wrote:
> >
> > > > I'm going to trim your code to what looks like the relevant portion of
> > > > the HTML template, since that's where the easiest solution lies.
> >
> > > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
> >
> > > > [...]
> >
> > > > > � � list_listing.html
> >
> > > > > 
> > > > > Sight Seeings
> > > > > 
> > > > > {%if listing_result %}
> > > > > � � {% for n in listing_result %}
> > > > > � � � � {{n.list_channel}}
> > > > > � � {% endfor %}
> > > > > {% else %}
> > > > > � � not available
> > > > > {% endif %}
> > > > > 
> > > > > 
> >
> > > > [...]
> >
> > > > > I am displaying Listing_channels and Listing on same page. if some one
> > > > > click on any Listing_channels the corresponding Listing must display
> > > > > on same page. that is why i am also sending the Listing_channels
> > > > > object to list_listing.html page. if some one click first time on
> > > > > Listing_channels it shows the 
> > > > > urlhttp://127.0

Re: Change the url

2009-01-08 Thread Briel

Using urls with names will solve your problem.

Basically if you change your urls.py like this:

url(
r'^category/listing_view/(?P\w+)/$',
   'mysite.library.views.listing_view',
   name = 'name_for_this_view'
),

What I have done is to add a name to the url for convenience I also
used the url() function. This name can now be used instead of the link
to your view. So if you were to change the site structure, when
changes would be made to your urlconf, django would then be able to
figure things out for you. In this version your new link would look
like this:

{{n.list_channel}}


In the docs you can read about it at
url(): http://docs.djangoproject.com/en/dev/topics/http/urls/#url
naming: http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

Good luck.
-Briel

On 8 Jan., 12:41, Praveen <praveen.python.pl...@gmail.com> wrote:
> Hi Malcolm i am very new bie of Django. i read through
> get_absolute_url but do not know how to use.
> What you have given the answer i tried with that and its working fine
> but my senior asked me what will happen if i change the site name then
> every where you will have to change url
> mysite.library.views.listing_view.
>
> so they told me to use get_absolute_url
>
> i wrote get_absolute_ul in models.py
>     def get_absolute_url(self):
>         return "/listing/%i/" % self.id
> and i am trying to use in my html page template but i don't know how
> to use
>
>  {{n.list_channel}} li>
>
> then again same problem. first time when some one click on link it
> works fine but second time it appends the link 
> likehttp://127.0.0.1:8000/category/listing_view/3/3
>
> Please give me some idea
>
> On Jan 8, 3:37 pm, Praveen <praveen.python.pl...@gmail.com> wrote:
>
> > Thank you so much Malcolm.
> > every one gives only the link and tell to read but your style of
> > solving the problem is amazing. how you explained me in a nice way
> > that i can never ever find in djangoproject.com.
> > Thanks you so much malcom
>
> > On Jan 8, 3:23 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> > wrote:
>
> > > I'm going to trim your code to what looks like the relevant portion of
> > > the HTML template, since that's where the easiest solution lies.
>
> > > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > > [...]
>
> > > >     list_listing.html
>
> > > > 
> > > > Sight Seeings
> > > > 
> > > > {%if listing_result %}
> > > >     {% for n in listing_result %}
> > > >         {{n.list_channel}}
> > > >     {% endfor %}
> > > > {% else %}
> > > >     not available
> > > > {% endif %}
> > > > 
> > > > 
>
> > > [...]
>
> > > > I am displaying Listing_channels and Listing on same page. if some one
> > > > click on any Listing_channels the corresponding Listing must display
> > > > on same page. that is why i am also sending the Listing_channels
> > > > object to list_listing.html page. if some one click first time on
> > > > Listing_channels it shows the 
> > > > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > > > but second time it appends 1 at the end and the url becomes
> > > >http://127.0.0.1:8000/category/listing_view/1/1
>
> > > The above code fragment is putting an element in the template that looks
> > > like
>
> > >         ...
>
> > > That is a relative URL reference and will be relative to the URL of the
> > > current page (which is .../category/listing_view/1/). In other words, it
> > > will be appended to that URL. One solution is to change the relative
> > > reference to look like
>
> > >         ...
>
> > > or, in template language:
>
> > >         {{n.list_channel}}
>
> > > That assumes you will only be displaying this template
> > > as /listing_view/1/ (or with a different number as the final
> > > component), since it will *always* remove the final component and
> > > replace it with the id value.
>
> > > The alternative, which is a little less fragile, is to use the "url"
> > > template tag to include a URL that goes all the way back to the hostname
> > > portion. You could write
>
> > >         {{n.list_channel}}
>
> > > (I've put in some line breaks just to avoid unpleasant line-wrapping).
> > > The {% url ... %} portion will return "/category/listing_view/1/" -- or
> > > whatever the right n.id value is -- which will always be correct.
>
> > > Have a read 
> > > ofhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlif
> > > you're not familiar with the URL tag.
>
> > > Regards,
> > > Malcolm
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Praveen

Hi Malcolm i am very new bie of Django. i read through
get_absolute_url but do not know how to use.
What you have given the answer i tried with that and its working fine
but my senior asked me what will happen if i change the site name then
every where you will have to change url
mysite.library.views.listing_view.

so they told me to use get_absolute_url

i wrote get_absolute_ul in models.py
def get_absolute_url(self):
return "/listing/%i/" % self.id
and i am trying to use in my html page template but i don't know how
to use

 {{n.list_channel}}

then again same problem. first time when some one click on link it
works fine but second time it appends the link like
http://127.0.0.1:8000/category/listing_view/3/3

Please give me some idea

On Jan 8, 3:37 pm, Praveen <praveen.python.pl...@gmail.com> wrote:
> Thank you so much Malcolm.
> every one gives only the link and tell to read but your style of
> solving the problem is amazing. how you explained me in a nice way
> that i can never ever find in djangoproject.com.
> Thanks you so much malcom
>
> On Jan 8, 3:23 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
> wrote:
>
>
>
> > I'm going to trim your code to what looks like the relevant portion of
> > the HTML template, since that's where the easiest solution lies.
>
> > On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> > [...]
>
> > >     list_listing.html
>
> > > 
> > > Sight Seeings
> > > 
> > > {%if listing_result %}
> > >     {% for n in listing_result %}
> > >         {{n.list_channel}}
> > >     {% endfor %}
> > > {% else %}
> > >     not available
> > > {% endif %}
> > > 
> > > 
>
> > [...]
>
> > > I am displaying Listing_channels and Listing on same page. if some one
> > > click on any Listing_channels the corresponding Listing must display
> > > on same page. that is why i am also sending the Listing_channels
> > > object to list_listing.html page. if some one click first time on
> > > Listing_channels it shows the 
> > > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > > but second time it appends 1 at the end and the url becomes
> > >http://127.0.0.1:8000/category/listing_view/1/1
>
> > The above code fragment is putting an element in the template that looks
> > like
>
> >         ...
>
> > That is a relative URL reference and will be relative to the URL of the
> > current page (which is .../category/listing_view/1/). In other words, it
> > will be appended to that URL. One solution is to change the relative
> > reference to look like
>
> >         ...
>
> > or, in template language:
>
> >         {{n.list_channel}}
>
> > That assumes you will only be displaying this template
> > as /listing_view/1/ (or with a different number as the final
> > component), since it will *always* remove the final component and
> > replace it with the id value.
>
> > The alternative, which is a little less fragile, is to use the "url"
> > template tag to include a URL that goes all the way back to the hostname
> > portion. You could write
>
> >         {{n.list_channel}}
>
> > (I've put in some line breaks just to avoid unpleasant line-wrapping).
> > The {% url ... %} portion will return "/category/listing_view/1/" -- or
> > whatever the right n.id value is -- which will always be correct.
>
> > Have a read 
> > ofhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlif
> > you're not familiar with the URL tag.
>
> > Regards,
> > Malcolm
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Praveen

Thank you so much Malcolm.
every one gives only the link and tell to read but your style of
solving the problem is amazing. how you explained me in a nice way
that i can never ever find in djangoproject.com.
Thanks you so much malcom

On Jan 8, 3:23 pm, Malcolm Tredinnick 
wrote:
> I'm going to trim your code to what looks like the relevant portion of
> the HTML template, since that's where the easiest solution lies.
>
> On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
>
> [...]
>
>
>
> >     list_listing.html
>
> > 
> > Sight Seeings
> > 
> > {%if listing_result %}
> >     {% for n in listing_result %}
> >         {{n.list_channel}}
> >     {% endfor %}
> > {% else %}
> >     not available
> > {% endif %}
> > 
> > 
>
> [...]
>
> > I am displaying Listing_channels and Listing on same page. if some one
> > click on any Listing_channels the corresponding Listing must display
> > on same page. that is why i am also sending the Listing_channels
> > object to list_listing.html page. if some one click first time on
> > Listing_channels it shows the 
> > urlhttp://127.0.0.1:8000/category/listing_view/1/
> > but second time it appends 1 at the end and the url becomes
> >http://127.0.0.1:8000/category/listing_view/1/1
>
> The above code fragment is putting an element in the template that looks
> like
>
>         ...
>
> That is a relative URL reference and will be relative to the URL of the
> current page (which is .../category/listing_view/1/). In other words, it
> will be appended to that URL. One solution is to change the relative
> reference to look like
>
>         ...
>
> or, in template language:
>
>         {{n.list_channel}}
>
> That assumes you will only be displaying this template
> as /listing_view/1/ (or with a different number as the final
> component), since it will *always* remove the final component and
> replace it with the id value.
>
> The alternative, which is a little less fragile, is to use the "url"
> template tag to include a URL that goes all the way back to the hostname
> portion. You could write
>
>         {{n.list_channel}}
>
> (I've put in some line breaks just to avoid unpleasant line-wrapping).
> The {% url ... %} portion will return "/category/listing_view/1/" -- or
> whatever the right n.id value is -- which will always be correct.
>
> Have a read 
> ofhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#urlif
> you're not familiar with the URL tag.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Briel

Hi.
Instead of manually writing the url, you can instead use the {% url %}
tag, then Django would figure out what the correct url is. If you are
using url tags you should considder using named urls. The link with
url tag would end up something like this: {{n.list_channel}}

read about the url tag in the Django Doc
http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#url

-Briel

Praveen skrev:
> MODELS.py
>
> class Listing_channels(models.Model):
> list_channel = models.CharField(max_length = 20)
> visibility = models.BooleanField()
>
> def __unicode__(self):
> return self.list_channel
>
> class Listing(models.Model):
>   name = models.CharField(max_length=20)
>   description = models.TextField(max_length = 100)
>   website = models.URLField()
>   timing = models.CharField(max_length=20)
>   channels = models.ForeignKey(Listing_channels)
>   visibility = models.BooleanField()
>
>   def __unicode__(self):
>   return self.name
>
>URLS.py
>
>  (r'^category/listing_view/(?P\w+)/
> $','mysite.library.views.listing_view'),
>
>VIEWS.py
>
> def listing_view(request, id):
> report_list = get_object_or_404(Listing_channels, pk = id)
> listing_result = Listing_channels.objects.all()
> r = report_list. listing_set.all()
> print r
> return render_to_response("list_listing.html", {'report_list' :
> report_list,'r':r,'listing_result':listing_result})
>
>
> list_listing.html
>
> 
> Sight Seeings
> 
> {%if listing_result %}
> {% for n in listing_result %}
> {{n.list_channel}}
> {% endfor %}
> {% else %}
> not available
> {% endif %}
> 
> 
>  
>  {% if report_list  %}
>
>  
>   
>height="100px">Sight
> Seeings Details
>   
>   
>   
>   
> {% for t in r %}
> 
>   {{ t.name }}
> 
> 
>   {{ t.timing }}
> 
> 
>   {{ t.description }}
> 
> 
>   {{ t.website }}
> 
> 
> {% endfor %}
>   
>  {% else %}
>No names found
>
>   {% endif %}
>   
>
> I am displaying Listing_channels and Listing on same page. if some one
> click on any Listing_channels the corresponding Listing must display
> on same page. that is why i am also sending the Listing_channels
> object to list_listing.html page. if some one click first time on
> Listing_channels it shows the url 
> http://127.0.0.1:8000/category/listing_view/1/
> but second time it appends 1 at the end and the url becomes
> http://127.0.0.1:8000/category/listing_view/1/1
>
> I am trying to display like frameset left side all channels and right
> side description of that channel.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Change the url

2009-01-08 Thread Malcolm Tredinnick

I'm going to trim your code to what looks like the relevant portion of
the HTML template, since that's where the easiest solution lies.

On Thu, 2009-01-08 at 02:02 -0800, Praveen wrote:
[...]
> 
> list_listing.html
> 
> 
> Sight Seeings
> 
> {%if listing_result %}
> {% for n in listing_result %}
> {{n.list_channel}}
> {% endfor %}
> {% else %}
> not available
> {% endif %}
> 
> 

[...]
> I am displaying Listing_channels and Listing on same page. if some one
> click on any Listing_channels the corresponding Listing must display
> on same page. that is why i am also sending the Listing_channels
> object to list_listing.html page. if some one click first time on
> Listing_channels it shows the url 
> http://127.0.0.1:8000/category/listing_view/1/
> but second time it appends 1 at the end and the url becomes
> http://127.0.0.1:8000/category/listing_view/1/1

The above code fragment is putting an element in the template that looks
like

...

That is a relative URL reference and will be relative to the URL of the
current page (which is .../category/listing_view/1/). In other words, it
will be appended to that URL. One solution is to change the relative
reference to look like

...

or, in template language:

{{n.list_channel}}

That assumes you will only be displaying this template
as /listing_view/1/ (or with a different number as the final
component), since it will *always* remove the final component and
replace it with the id value.

The alternative, which is a little less fragile, is to use the "url"
template tag to include a URL that goes all the way back to the hostname
portion. You could write

{{n.list_channel}}

(I've put in some line breaks just to avoid unpleasant line-wrapping).
The {% url ... %} portion will return "/category/listing_view/1/" -- or
whatever the right n.id value is -- which will always be correct.

Have a read of
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url if
you're not familiar with the URL tag.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Change the url

2009-01-08 Thread Praveen

 MODELS.py

class Listing_channels(models.Model):
list_channel = models.CharField(max_length = 20)
visibility = models.BooleanField()

def __unicode__(self):
return self.list_channel

class Listing(models.Model):
name = models.CharField(max_length=20)
description = models.TextField(max_length = 100)
website = models.URLField()
timing = models.CharField(max_length=20)
channels = models.ForeignKey(Listing_channels)
visibility = models.BooleanField()

def __unicode__(self):
return self.name

   URLS.py

 (r'^category/listing_view/(?P\w+)/
$','mysite.library.views.listing_view'),

   VIEWS.py

def listing_view(request, id):
report_list = get_object_or_404(Listing_channels, pk = id)
listing_result = Listing_channels.objects.all()
r = report_list. listing_set.all()
print r
return render_to_response("list_listing.html", {'report_list' :
report_list,'r':r,'listing_result':listing_result})


list_listing.html


Sight Seeings

{%if listing_result %}
{% for n in listing_result %}
{{n.list_channel}}
{% endfor %}
{% else %}
not available
{% endif %}


 
 {% if report_list  %}

 

Sight
Seeings Details




{% for t in r %}

{{ t.name }}


{{ t.timing }}


{{ t.description }}


{{ t.website }}


{% endfor %}
  
 {% else %}
   No names found

  {% endif %}
  

I am displaying Listing_channels and Listing on same page. if some one
click on any Listing_channels the corresponding Listing must display
on same page. that is why i am also sending the Listing_channels
object to list_listing.html page. if some one click first time on
Listing_channels it shows the url http://127.0.0.1:8000/category/listing_view/1/
but second time it appends 1 at the end and the url becomes
http://127.0.0.1:8000/category/listing_view/1/1

I am trying to display like frameset left side all channels and right
side description of that channel.

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: change save url of imagefield

2007-03-05 Thread Benedict Verheyen

Jarosław Świerad schreef:
> On Monday 05 March 2007 09:42, Benedict Verheyen wrote:
>> Hi,
>>
>> i have a class with an imagefield.
>> I'm trying to add the current logged in user to the path where the image
>> field is saved.
>> image = models.ImageField(upload_to="img/_USER_/icons/", blank=True )
>>
>> _USER_ is a placeholder for the "real" user.
> 
> How about request.user?
> 
> Check out: 
> http://www.djangoproject.com/documentation/authentication/#limiting-access-to-logged-in-users
> 

Yeah, i tried using that in my model:
...
image = models.ImageField(upload_to="img/%s/icons/" %
threadlocals.get_current_user(), blank=True )
...

Didn't work, the images ended up in img/None/icons.

I then tried to save the image myself in my view:
import os.path
sep = os.path.sep
# build the new path
path = "img" + sep + str(request.user) + sep + "icons"
path = path + os.path.sep + os.path.basename(icon.image)
img = open(icon.image,'rb')
icon.save_image_file(path,img.read())
img.close()
icon.save()

This doesn't work either, it seems to always go for the path
specified in upload_to.

Thanks
Benedict


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: change save url of imagefield

2007-03-05 Thread Jarosław Świerad
On Monday 05 March 2007 09:42, Benedict Verheyen wrote:
> Hi,
>
> i have a class with an imagefield.
> I'm trying to add the current logged in user to the path where the image
> field is saved.
> image = models.ImageField(upload_to="img/_USER_/icons/", blank=True )
>
> _USER_ is a placeholder for the "real" user.

How about request.user?

Check out: 
http://www.djangoproject.com/documentation/authentication/#limiting-access-to-logged-in-users

-- 
Jarosław Świerad
.: Programowanie jest sztuką
.: Programista artystą


pgpSXCXVBzdOR.pgp
Description: PGP signature


change save url of imagefield

2007-03-05 Thread Benedict Verheyen

Hi,

i have a class with an imagefield.
I'm trying to add the current logged in user to the path where the image
field is saved.
image = models.ImageField(upload_to="img/_USER_/icons/", blank=True )

_USER_ is a placeholder for the "real" user.

def add_icon(request):
IconForm = forms.models.form_for_model(Icon)
if request.method == 'POST':
form = IconForm(request.POST)
if form.is_valid():
icon = form.save(commit=False)
icon.image = icon.image.replace("_USER_",str(request.user))
icon.save()
return HttpResponseRedirect("/")
else:
form = IconForm()
t = loader.get_template('main/add_icon.html')
c = Context({
'form': form,
})
return HttpResponse(t.render(c))

This doesn't work as it's still saved with _USER_ in the path.
Any ideas?

Thanks,
Benedict


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---