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:
Hey Adam,
That patch looks pretty decent -- go ahead and file a ticket!
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com