2011-09-15 110 views
7

我有下面的「RecordEntry」模式簡單投稿頁面的應用程序:我需要一個小部件來瀏覽文件系統

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 

的PDF,HTML,ZIP和PSD領域將保持路徑對這些對象的哪些將作爲模板的鏈接顯示。我的問題是,是否有辦法避免每次都在這些字段中輸入整個路徑?是否有某種類型的窗口小部件可以讓我瀏覽文件系統並捕獲單擊的任何項目的路徑?

+0

爲什麼不直接使用FileField? https://docs.djangoproject.com/en/1.3/ref/models/fields/#filefield – Brandon

+0

我可能會誤解,但我認爲FileField實際上已將文件上傳到設置中指定的媒體目錄。我只想引用已經存在於服務器上的文件的路徑。 FileField可能允許我這樣做(我正在研究它),我只是假設它不能。 – kjarsenal

+0

是的,它也處理上傳。要瀏覽目錄,請嘗試使用FilePathField:https://docs.djangoproject.com/en/1.3/ref/models/fields/#filepathfield – Brandon

回答

1

這可以讓你在任何地方?

Is there a filesystem plugin available for django?

有一個有點如何到這裏的:

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

,但你必須把它做成一個選擇窗口小部件自己。

+2

Filebrowser/Grapelli是比我需要的方式。我只需要一個類似WYSIWYG程序的小部件..一個打開目錄窗口的按鈕;你導航到你的目標文件,單擊,並且該路徑被傳送到你的代碼中。顯然,它涉及的代碼比我認爲的要多。 – kjarsenal

相關問題