From ef082ebb84f00e38af4e8880d04e8365c2766d34 Mon Sep 17 00:00:00 2001 From: Mykola Kokalko Date: Thu, 2 May 2019 10:42:10 +0200 Subject: Fixed #29529 -- Allowed models.fields.FilePathField to accept a callable path. --- docs/ref/models/fields.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'docs/ref') diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index e352e8b007..fbcba2bd66 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -868,6 +868,23 @@ directory on the filesystem. Has three special arguments, of which the first is Required. The absolute filesystem path to a directory from which this :class:`FilePathField` should get its choices. Example: ``"/home/images"``. + ``path`` may also be a callable, such as a function to dynamically set the + path at runtime. Example:: + + import os + from django.conf import settings + from django.db import models + + def images_path(): + return os.path.join(settings.LOCAL_FILE_DIR, 'images') + + class MyModel(models.Model): + file = models.FilePathField(path=images_path) + + .. versionchanged:: 3.0 + + ``path`` can now be a callable. + .. attribute:: FilePathField.match Optional. A regular expression, as a string, that :class:`FilePathField` -- cgit v1.3