Skip to content

Commit

Permalink
[1.7.x] Fixed #24613 -- Added example to QuerySet.defer() documentation
Browse files Browse the repository at this point in the history
Backport of dd99f57 from master
  • Loading branch information
Naddiseo authored and timgraham committed Apr 22, 2015
1 parent 2dc82a8 commit bcd7f39
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/ref/models/querysets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,30 @@ one, doing so will result in an error.
reader, is slightly faster and consumes a little less memory in the Python
process.

For example, both of these models use the same underlying database table::

class CommonlyUsedModel(models.Model):
f1 = models.CharField(max_length=10)

class Meta:
managed = False
db_table = 'app_largetable'

class ManagedModel(models.Model):
f1 = models.CharField(max_length=10)
f2 = models.CharField(max_length=10)

class Meta:
db_table = 'app_largetable'

# Two equivalent QuerySets:
CommonlyUsedModel.objects.all()
ManagedModel.objects.all().defer('f2')

If many fields need to be duplicated in the unmanaged model, it may be best
to create an abstract model with the shared fields and then have the
unmanaged and managed models inherit from the abstract model.

.. note::

When calling :meth:`~django.db.models.Model.save()` for instances with
Expand Down

0 comments on commit bcd7f39

Please sign in to comment.