db.models.fields.related.RelatedManager.create()

create(**kwargs) Creates a new object, saves it and puts it in the related object set. Returns the newly created object: >>> b = Blog.objects.get(id=1) >>> e = b.entry_set.create( ... headline='Hello', ... body_text='Hi', ... pub_date=datetime.date(2005, 1, 1) ... ) # No need to call e.save() at this point -- it's already been saved. This is equivalent to (but much simpler than): >>> b = Blog.objects.get(id=1) >>> e = Entry( ... blog=b, .

db.models.fields.related.RelatedManager.clear()

clear() Removes all objects from the related object set: >>> b = Blog.objects.get(id=1) >>> b.entry_set.clear() Note this doesn’t delete the related objects – it just disassociates them. Just like remove(), clear() is only available on ForeignKeys where null=True and it also accepts the bulk keyword argument.

db.models.fields.related.RelatedManager.add()

add(*objs, bulk=True) Adds the specified model objects to the related object set. Example: >>> b = Blog.objects.get(id=1) >>> e = Entry.objects.get(id=234) >>> b.entry_set.add(e) # Associates Entry e with Blog b. In the example above, in the case of a ForeignKey relationship, QuerySet.update() is used to perform the update. This requires the objects to already be saved. You can use the bulk=False argument to instead have the related manager perform the update by c

db.models.fields.related.RelatedManager

class RelatedManager A “related manager” is a manager used in a one-to-many or many-to-many related context. This happens in two cases: The “other side” of a ForeignKey relation. That is: from django.db import models class Reporter(models.Model): # ... pass class Article(models.Model): reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE) In the above example, the methods below will be available on the manager reporter.article_set. Both sides of a ManyToManyField

db.models.fields.files.FieldFile.url

FieldFile.url A read-only property to access the file’s relative URL by calling the url() method of the underlying Storage class.

db.models.fields.files.FieldFile.size

FieldFile.size The result of the underlying Storage.size() method.

db.models.fields.files.FieldFile.save()

FieldFile.save(name, content, save=True) [source] This method takes a filename and file contents and passes them to the storage class for the field, then associates the stored file with the model field. If you want to manually associate file data with FileField instances on your model, the save() method is used to persist that file data. Takes two required arguments: name which is the name of the file, and content which is an object containing the file’s contents. The optional save argument

db.models.fields.files.FieldFile.open()

FieldFile.open(mode='rb') [source] Opens or reopens the file associated with this instance in the specified mode. Unlike the standard Python open() method, it doesn’t return a file descriptor. Since the underlying file is opened implicitly when accessing it, it may be unnecessary to call this method except to reset the pointer to the underlying file or to change the mode.

db.models.fields.files.FieldFile.name

FieldFile.name The name of the file including the relative path from the root of the Storage of the associated FileField.

db.models.fields.files.FieldFile.delete()

FieldFile.delete(save=True) [source] Deletes the file associated with this instance and clears all attributes on the field. Note: This method will close the file if it happens to be open when delete() is called. The optional save argument controls whether or not the model instance is saved after the file associated with this field has been deleted. Defaults to True. Note that when a model is deleted, related files are not deleted. If you need to cleanup orphaned files, you’ll need to handle