0

I'm trying to manage folder navigation in django 1.6, my goals is to get something like the url pattern you can see on Dropbox website. The url looks like to : 'Home/Folder/Subfolder'.

I've an issue when there is two folders with the same name but with a different primary key of course. These folders are located in a different directory.

First, in my template, i was sending the name of the folder as a get parameter. In order to get the right folder object in my view when i had two folder with the same name, i have changed my url conf passing the folder pk as a post data (similar to this answer : https://stackoverflow.com/a/6118735/2112198).

It works, but i would like to find a better way to achieve this. Could i pass the pk as a get parameter and rewrite the url next in the view to get only the folder name in the url browser ?

Community
  • 1
  • 1
Burrich
  • 1,214
  • 1
  • 16
  • 15

1 Answers1

1

If you need two identical urls to represent two different objects then your url scheme is conceptually flawed.

With the caveat... clearly this works for Dropbox. It is worth thinking about why this works: in Dropbox you are logged in as a specific user. Each user has their own folder structure, but a user can't have two folders with the same name.

i.e. there is a hidden variable (user id) that is added to the folder path in order to locate a unique object.

Alternatively, if you are just trying to work around this simpler problem:

Home/Documents/Work
Home/Pictures/Work

i.e. two folders named Work then you just need to consider the whole path like Pictures/Work vs Documents/Work in order to disambiguate them.

Anentropic
  • 32,188
  • 12
  • 99
  • 147
  • For two different folder objects with the same name, urls are always different but the parent folder could have the same name too. e.g., 'Folder/.../Parent/Subfolder' and 'AnotherFolder/.../Parent/Subfolder'. As you said, i'm using user session to find the right folder, but i forget to talk about the parent field in my original post, which can be the same. – Burrich Jun 12 '14 at 17:44
  • 1
    Still... you should be able to distinguish based on the whole folder path rather than just the last segment and its parent – Anentropic Jun 12 '14 at 20:24
  • Thanks for insisting on the folder path. I've added a path column to my folder model, best solution indeed. I shoud have think about this solution earlier, but i didn't developp the model part of my application. I was thinking that i wouldn't have to modify the existing model. – Burrich Jun 13 '14 at 13:24