Hi Praveen
It's not always an easy task being a developer.

However, I don't see the point in using Django, if you're not also
using all of the tools that available because you need a designer that
only know strict HTML, and don't know anything about the process. With
all the vars and tags you're already using like {% for %} ect, I have
a hard time seeing the advantage using such designers. I but guess it
all comes down to how you want to organize things, and here it's the
seniors that make that choice. Not a situation I myself am in.

If you have to write get_absolute_url(), you should get a read on
reverse() that kip wrote about. It can get the urls for you in most
cases.

Good Luck with the project.
-Briel

On 9 Jan., 10:20, Praveen <praveen.python.pl...@gmail.com> wrote:
> Hi Briel again my senior gave me other idea and they gave me a nice
> reason why they want me to use get_absolute_url()
>
> Given our new understanding of what the best practice is, the workflow
> for a template designer, who shouldn’t need to know or understand
> programming, is:
>
>    1. Ignore the documentation’s preference for {% url %} and use what
> makes sense in a given circumstance.
>    2. In order to know what makes sense in a given circumstance,
> figure out whether the view you want to link to is an object detail
> view or not.
>    3. If it’s an object detail view, use get_absolute_url.
>    4. If not, dig through the Python code to find the friendly name
> your programmer has given to the view you want to link to. You’ll want
> to look at URL configurations for this. Please note that these URL
> configurations may be strewn across many apps, including some third-
> party apps that don’t reside in your project at all. Just read the
> Python import statements in your base URL configuration and you should
> be able to find them. Don’t know what a Python import statement or a
> base URL configuration is?
>    5. Once you’ve found the friendly name, read the regular
> expressions in the URL configuration to figure out what arguments need
> to be passed to the {% url %} tag. It may help to find and read the
> associated view function. I know you probably don't know Python or
> regular expressions, but sometimes life is hard.
> Construct your {% url %} tag. Use filters to parse data like dates and
> times into the format expected by your view function. If the filter
> you're looking for doesn't exist, you may need to write it. Except you
> can't, because you don't know Python. Sorry about that.
> Be very careful not to make any typos in your {% url %} tag, or you
> will almost certainly face a NoReverseMatch exception, which will be
> nonsense to you and very difficult to debug.
>
> If you find yourself in a situation with designers who would have
> trouble fully grasping all the steps you’ve outlined above (and that’s
> no knock on the designers, that shouldn’t really be their main job),
> then the job falls to the developer to make it simpler.
>
> For the rest of the cases — namely, those where you’re dealing with a
> name plus arguments and you’re going to be using it over and over (and
> hence it’ll be tedious to write out a {% url %} call every time), your
> friendly local developer can supply you with a shortcut in the form of
> a method you can hit on an object, decorated with permalink, as often
> happens with get_absolute_url.
>
> It’s also worth noting that you can often simplify repetition within a
> template by using one of the newer features of the {% url %} tag: in
> the form {% url some_pattern_name arg1=foo,arg2=bar as some_url %}, it
> sets the variable some_url for reuse.
>
> So basically, to me, this comes down to developers and designers
> working together to share information: designers explaining what they
> need in terms of backend support, and developers explaining what
> support they can provide and how to use it.
>
> I think their points are also positive and now i am going to use
> get_absolute_url().
>
> 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 %}
> > >         <li> <a href="{{n.get_absolute_url}}">{{n.list_channel}}</a></
> > > li>
> > >     {% endfor %}
> > > {% else %}
> > >     <p>not available</p>
> > > {% endif %}
> > > </ul>
>
> > > 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<id>\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:
>
> > > > <li><a href="
> > > >            {% url name_for_this_view n.id %}
> > > >         ">{{n.list_channel}}</a></li>
>
> > > > 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
>
> > > > > <li> <a href="{{get_absolute_url}}{{n.id}}">{{n.list_channel}}</a></
> > > > > 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
>
> > > > > > > > <div id="leftpart">
> > > > > > > > <h3>Sight Seeings</h3>
> > > > > > > > <ul>
> > > > > > > > {%if listing_result %}
> > > > > > > > {% for n in listing_result %}
> > > > > > > > <li><a href="{{n.id}}">{{n.list_channel}}</a></li>
> > > > > > > > {% endfor %}
> > > > > > > > {% else %}
> > > > > > > > <p>not available</p>
> > > > > > > > {% endif %}
> > > > > > > > </ul>
> > > > > > > > </div>
>
> > > > > > > [...]
>
> > > > > > > > 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
>
> ...
>
> læs mere »
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to