Description
Is there a way to map existing files with the same schema that do not match a repeatable pattern on disk to a datafiles Model instance manually? The use case is config files spread across arbitrary-depth subfolders below a top-level project directory. Using glob I can find the files I am interested in mapping, but I am not having much success creating mapped instances of those discovered files.
I have tried:
- Overriding
Model.Meta.dataclass_pattern
with each discovered files path and callingModel.objects.get()
- Creating instances of a model with default values and no
pattern
defined and then overriding both theinstance.Meta.datafiles_pattern
andinstance.datafile.path
attributes on the instance, with the correct path for the discovered file, before callinginstance.datafile.load()
.
However in both cases this results in an odd behaviour where all instances with nested attributes contain pointers to the most recently loaded files' nested object rather than their own 🤦♂️
Is this a completely unsupported use-case, or is there another way to use datafiles
to map files discovered outside of the supported 'pattern' construct to instances of a datafiles Model? Thank you!