2

This is my models.py. Displaying in folder structure format.

class Folder(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='userfolders')
    folder = models.ForeignKey("self", on_delete=models.CASCADE,related_name='folders', null=True, blank=True)
    name = models.CharField(_('Folder Name'), max_length=70)

class File(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='userfiles')
    folder = models.ForeignKey(Folder, on_delete=models.CASCADE, related_name='folderfiles')
    description = models.CharField(_('File Description'), max_length=70)
    location = models.FileField(_('Location of the File'), upload_to=file_location_path, null=True, blank=True)

In the model as you can see i have folder with a self foreign key and file can be associated to a folder.

Folder------+---Old Folder
            +---Folder1-+--Cats.jpg
            |           +--File1.jpg
            +---File1.txt
File
Folder New -+---Puppy.jpg
            +---Dogs----+--Dog1.jpg
                        +--Dog2.jpg
                        +--Dog3.jpg

| 1st level | 2nd level | 3rd level |

How can i display the 1st level first and then if the user selects a folder then it should show its content. for example, if Folder New is selected then the users should see file named Puppy.jpg and folder named Dogs. Is this possible?

Mike Pinkman
  • 169
  • 9

0 Answers0