Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all available values for FilePathField in Django 1.5?

Tags:

python

django

I have a model, which has FilePathField attribute. It has a folder to search, regular expression to match and other needed parameters.

I need a standard method to get the list of all available for this FilePathField paths. Or it does not exist?

like image 209
Charlie Avatar asked Jan 19 '26 09:01

Charlie


1 Answers

No, there isn't one. You can write your own using path, match and recursive. However, this is how the admin widget form for FilePathField gets all the paths - https://github.com/django/django/blob/master/django/forms/fields.py#L999

from django.forms.fields import FilePathField
a = FilePathField(path='/path')
print a.choices
like image 94
manojlds Avatar answered Jan 22 '26 02:01

manojlds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!