models - Django URL Slugs -


i have comment , post model.

i want url come out /post//comment//

but unsure how set up.

my post model has this:

@python_2_unicode_compatible class post(models.model):     ...     slug = models.slugfield(unique=true)      @models.permalink     def get_absolute_url(self):         return 'appname:post', (self.slug,) 

can comment model have:

@python_2_unicode_compatible class comment(models.model):     ...     slug = models.slugfield(unique=true)      @models.permalink     def get_absolute_url(self):         return 'appname:post:comment', (self.slug,) 

or how hook get_absolute_url url comes out way mentioned? or there better way?

@python_2_unicode_compatible class comment(models.model):     title = models.charfield(max_length=100)     body = models.charfield(max_length=1000)     creation_date = models.datetimefield(auto_now_add=true)     last_updated = models.datetimefield()     author = models.foreignkey(person, related_name='authors')     project = models.foreignkey(project, related_name='comments', null=true, blank=true)     task = models.foreignkey(task, related_name='comments', null=true, blank=true)     slug = models.slugfield(unique=true)      def __str__(self):         return self.title          @models.permalink     def get_absolute_url(self):         if self.project:             return ('comment', (), {                 'project': self.task.id,                 'slug': self.slug,                 'id': self.id,             })                     elif self.task:             return ('comment', (), {                 'project': self.task.project.id,                 'task': self.task.id,                 'slug': self.slug,                 'id': self.id,             }) 

and hook urls.py use necessary id's url named 'comment'


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -