7

I have a simple posting page app with the following "RecordEntry" model:

class RecordEntry(models.Model):
    client = models.ForeignKey(PostPage)
    filename = models.CharField(max_length=64, unique=False, blank=True, null=True)
    descriptor = models.CharField(max_length=64, unique=False, blank=True, null=True)
    date = models.DateField(_("Date"), default=datetime.date.today)
    post_type = models.CharField(max_length=50, choices=POST_CHOICES)
    round = models.CharField(max_length=50, choices=ROUND_CHOICES)
    pdf = models.CharField(max_length=100, unique=False, blank=True, null=True)
    html = models.CharField(max_length=100, unique=False, blank=True, null=True)
    zip = models.CharField(max_length=100, unique=False, blank=True, null=True)
    psd = models.CharField(max_length=100, unique=False, blank=True, null=True)

    def __unicode__ (self):
            return return u'%s %s' % (self.client, self.filename)

    class Admin: 
            pass

the pdf, html, zip, and psd fields will hold paths to those objects which will be displayed as links by the template. My question is, is there a way I can avoid actually typing the entire path in these fields every time? Is there a widget of some type that will allow me to browse the filesystem and capture the path of any item I click on?

kjarsenal
  • 934
  • 1
  • 12
  • 35
  • Why not just use the FileField? https://docs.djangoproject.com/en/1.3/ref/models/fields/#filefield – Brandon Taylor Sep 15 '11 at 13:28
  • I may be mistaken but I thought the FileField actually uploaded the file to a media directory specified in settings. I just want to reference the path to files that already live on the server. FileField may allow me to do that (I'm studying it now), I just assumed that it could not. – kjarsenal Sep 15 '11 at 13:45
  • Yes, it also handles uploading. For browsing a directory, try the FilePathField: https://docs.djangoproject.com/en/1.3/ref/models/fields/#filepathfield – Brandon Taylor Sep 15 '11 at 14:11
  • Yeah, I tried FilePathField which does work. The problem is that each record object has file assets that live in different directories on the server. The FilePathField makes you declare an absolute path as an argument. That means that the browsing directory would have to encompass all of the asset directories. There's gotta be something more practical. Thanks though. – kjarsenal Sep 15 '11 at 14:29
  • I see. Yes, that does make things more complicated. I look forward to seeing what you come up with! – Brandon Taylor Sep 15 '11 at 14:37
  • You want to let the *client* browse the file system on the *server* yes? You know this can open a big bag of security holes? I guess that's probably why you want a readymade solution :) – Spacedman Sep 15 '11 at 15:12

1 Answers1

1

This get you anywhere?

Is there a filesystem plugin available for django?

There's a bit of a how-to here:

http://rfc1437.de/page/writing-a-simple-filesystem-browser-with-django/

but you'd have to make it into a selection widget yourself.

Community
  • 1
  • 1
Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • 2
    Filebrowser/Grapelli is way more than I need. I just need a widget like the ones in the WYSIWYG programs.. a button that opens a directory window; you navigate to your target file, click, and the path propigates into your code. Obviously, it's more involved to code than I thought it would be. – kjarsenal Sep 15 '11 at 15:52