On 3/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Adrian Holovaty wrote: > > The convention is to put the URL-creation logic in your models, in a > > get_absolute_url() method. Here's a quick example: > > > > class Person(meta.Model): > > gender = meta.CharField(maxlength=1) # 'm' or 'f' > > full_name = meta.CharField(maxlength=50) > > > > def get_absolute_url(self): > > return '/people/%s/%s/' % (self.gender, > > self.full_name.lower().replace(' ', '')) > > I find this *really* surprising. All discussions and examples I've seen > so far are quite strict about the fact that models should be separate > from presentation logic. See the various discussions about "how can my > model get access to request.user?" here in this group. These arguments > made (make) perfect sense to me. > > And now you're encoding URLs (which are, in my mind, definitely > presentation-related) in the models? To me, this seems strange and > unnatural. Why should a "Book" model care wether it has a view that > lives under "/library" or under "/amazon/shoppingcart" or under > "/thingtostopthetablefromwobbling" ? It's a book. It has properties. It > knows how to tell me its title. > > But it shouldn't care wether it's being read or being used to prop up > furniture. > > Or am I misunderstanding something here? > > Daniel >
Because I think model in Django is not a simple data wrapper layer, but also a representation layer in many situations. If you don't want model do much, so you need do such things(create url) in other places. And if there is not a good way to create url, I think create url by model itself is a handy way. And I think there should be a good way to create url, which will consider different applications, functions, and object_ids. Even user_id in it. -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---