copy_objects#
- ADR.copy_objects(object_type: Session | Dataset | type[Item] | type[Template], target_database: str, *, query: str = '', target_media_dir: str | Path = '', test: bool = False) int#
Copy ADR objects (and associated media) between databases.
This method:
Queries objects of the given type from the source database (currently hard-coded to
"default").For
Itemobjects, ensures theirSessionandDatasetare also present in the target database, creating them as needed.For
Templateobjects, only copies root templates (children are copied recursively).Copies media files to a target media directory, optionally rebuilding 3D geometry files.
- Parameters:
- object_typetype
One of
Session,Dataset,Itemsubclass, orTemplate.- target_database
str Django database alias to copy into.
- query
str, default: “” ADR query string used to select objects from the source DB.
- target_media_dir
strorPath, default: “” Target directory for media files, required when copying items with associated files and the target database is not SQLite.
- testbool, default:
False If
True, do not actually write anything; just log and return the count of objects that would be copied.
- Returns:
intNumber of objects copied (or that would be copied in test mode).
- Raises:
ADRExceptionIf misconfigured (e.g. missing DB aliases, invalid media directory, non-top-level templates, or copy errors).