Forms¶
FileOrPathField
¶
Bases: MultiValueField
Form field that accepts either an uploaded file or a typed server-side path.
If a file is uploaded it is saved to a temporary directory and the path
to that temp file is returned as the cleaned value (a plain str).
If only a path string is typed that string is returned directly.
Typical usage in add_arguments::
from django_admin_runner import FileOrPathField
parser.add_argument("--source", widget=FileOrPathField(), help="CSV path or upload")
Source code in src/django_admin_runner/forms.py
FileOrPathWidget
¶
Bases: MultiWidget
Renders a file-upload input and a text-path input side by side.
The user can either upload a file or type a path on the server.
When ADMIN_RUNNER_UPLOAD_PATH is not set, the file input is hidden
and only the text path input is shown.
Source code in src/django_admin_runner/forms.py
form_from_command
¶
Build a Django Form class by introspecting command_name's argparse parser.
Both optional (--flag) and positional arguments are included; positional
arguments preserve the required=True constraint from argparse.
Filtering rules (applied in order):
- Default Django management params are always excluded.
- Arguments with
hidden=True(custom kwarg onadd_argument) are excluded. exclude_paramsfrom the registry entry are excluded.- If
paramsallowlist is set, only thosedestnames are kept.
Widget / field override priority (highest wins):
widget=<instance>kwarg onadd_argument()— specified in the command itself, closest to the argument definition.widgetsdict from theregister_commanddecorator.- Auto-detected from the argparse action type (uses Django admin widgets as the base so the form blends with the rest of the admin interface).
If the value at priority 1 or 2 is a :class:~django.forms.Field instance it
replaces the auto-detected field entirely (widget + validation). If it is a
:class:~django.forms.Widget instance the auto-detected field is kept but its
widget is swapped.
User-specified widgets (priorities 1 and 2) are never overridden by the Unfold auto-replacement. Auto-detected fields (priority 3) receive Unfold widgets when Unfold is installed.
If the registry entry has form_class set, it is returned directly —
no auto-generation, no Unfold replacement.
Source code in src/django_admin_runner/forms.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |