1

I want to create URLs for CMS portion of project I have following models

class Category(models.Model):
    name = models.CharField(max_length=150)
    parent = models.ForeignKey('self', blank=True, null=True)

class Page(models.Model):
    title = models.CharField(max_length=255)
    content = models.TextField()
    slug = models.CharField(max_length=255)
    category = models.ForeignKey(Category, related_name='pages')

I want the following URL structure for my categories

/categories/{parent category}/
/categories/{parent category}/{child category}/.../{child category}/pages/

How would I accomplish this with DRF-Extensions or any other plugin?

Ubaid
  • 431
  • 4
  • 14
  • why you need recursive, if your categories has unique id? – Brown Bear Oct 30 '17 at 14:10
  • Recursive because, I am planning on creating variable number of child categories. I don't know how to set this behavior with DRF-Extension Nested Routers (Pretty new to Django). And I don't want to explicitly set views and routes for each child category. – Ubaid Oct 30 '17 at 19:03
  • but you don need the recursive route to get category from url, it is enough only id – Brown Bear Oct 30 '17 at 19:25
  • Can you please elaborate with an example? – Ubaid Oct 30 '17 at 19:33

1 Answers1

0

There is a package for recursive serialization under DRF.

https://github.com/heywbj/django-rest-framework-recursive

There is an earlier discussion on stackoverflow: Django rest framework nested self-referential objects

wjin
  • 954
  • 1
  • 8
  • 13