Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
Adds docs on using Artifact with bulk_create()
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Bouterse committed Jul 25, 2018
1 parent d0aa104 commit 80bfd47
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pulpcore/pulpcore/app/models/content.py
Expand Up @@ -12,7 +12,20 @@ class Artifact(Model):
"""
A file associated with a piece of content.
When creating an Artifact, the file provided is moved into place by Pulp.
When calling `save()` on an Artifact, if the file is not stored in Django's storage backend, it
is moved into place then.
Artifact is compatible with Django's `bulk_create()` method, but you have to move the file into
the backend yourself before using an Artifact in a `bulk_create()` call. Here is a useful
snippet for saving a file into the storage backend manually:
>>> from django.core.files import File
>>> from django.core.files.storage import default_storage
>>> with open(src_path, mode='rb') as input_file:
>>> django_file_obj = File(input_file)
>>> default_storage.save(dst_path, django_file_obj)
>>> my_artifact.file = dst_path # Now the artifact is safe to use with bulk_create()
Fields:
Expand Down

0 comments on commit 80bfd47

Please sign in to comment.