Skip to content

Best way to map existing files to Model instances #236

Open
@kgpayne

Description

@kgpayne

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 calling Model.objects.get()
  • Creating instances of a model with default values and no pattern defined and then overriding both the instance.Meta.datafiles_pattern and instance.datafile.path attributes on the instance, with the correct path for the discovered file, before calling instance.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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions