Friday, October 14, 2011

Re: django 1.3: how to use get_abolute_url in class based generic views

On 13 October 2011 23:57, Andriyko <ahrytskiv@gmail.com> wrote:
urlpatterns = patterns('django.views.generic.dates',
(r'^(?P<year>\d{4})/v/(?P<day>\d{2})/(?P<slug>[-\w]+)/
$', DateDetailView.as_view(template_name='blog/article_detail.html',
**entry_info_dict)),
)
Hi,
You are using
(?P<month>\w{3})
but in get_absolute_url you are using
self.pub_date.strftime("%m").lower(),
referring to http://docs.python.org/library/time.html#time.strftime
%m return Month as a decimal number [01,12].
this won't never work
You should use %b instead of %m
This should work
HTH
Fabrizio

 
===== models.py ====

class Article(models.Model):
   ......
  # with django 1.2 was
      @models.permalink
   def get_absolute_url(self):
       return ('article_detail', (), {  'year':
self.pub_date.strftime("%Y"),
                                        'month':
self.pub_date.strftime("%m").lower(),
                                        'day':
self.pub_date.strftime("%d"),
                                        'slug': self.slug })
  # how should it look with django 1.3 ??????


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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate