FilePathField blank=True

41 views
Skip to first unread message

Adam

unread,
May 1, 2006, 7:23:32 PM5/1/06
to Django users
(in M-R) I have a model with this field:

image = models.FilePathField(path='/my/path', blank=True, null=True)

In the admin interface, the image field shows up dimmed like the rest
of the optional fields. However the select list lists all the files in
/my/path, without any blank option. So you are in effect forced to
select a file.

I looked around in django/forms/__init__.py, and I think I found a
likely place to change this behavior. Is this patch-worthy? Do people
disagree with how I think this should work?

(Of course I'd clean this up and move the import to the proper place in
a patch)

--- django/forms/__init__.py (revision 2802)
+++ django/forms/__init__.py (working copy)
@@ -874,7 +874,8 @@
if match is not None:
import re
match_re = re.compile(match)
- choices = []
+ from django.db import models
+ choices = not is_required and models.BLANK_CHOICE_DASH[:] or
[]
if recursive:
for root, dirs, files in os.walk(path):
for f in files:

Adrian Holovaty

unread,
May 2, 2006, 3:06:18 PM5/2/06
to django...@googlegroups.com
On 5/1/06, Adam <leftw...@gmail.com> wrote:
> (in M-R) I have a model with this field:
>
> image = models.FilePathField(path='/my/path', blank=True, null=True)
>
> In the admin interface, the image field shows up dimmed like the rest
> of the optional fields. However the select list lists all the files in
> /my/path, without any blank option. So you are in effect forced to
> select a file.
>
> I looked around in django/forms/__init__.py, and I think I found a
> likely place to change this behavior. Is this patch-worthy? Do people
> disagree with how I think this should work?
>
> (Of course I'd clean this up and move the import to the proper place in
> a patch)

Hey Adam,

That patch looks pretty decent -- go ahead and file a ticket!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

Reply all
Reply to author
Forward
0 new messages