2011-09-15 48 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

相关问题