Kaydet (Commit) fe533fc5 authored tarafından Richard Eames's avatar Richard Eames Kaydeden (comit) Tim Graham

[1.8.x] Fixed #24613 -- Added example to QuerySet.defer() documentation

Backport of dd99f577 from master
üst 322b9c90
...@@ -1379,6 +1379,30 @@ one, doing so will result in an error. ...@@ -1379,6 +1379,30 @@ one, doing so will result in an error.
reader, is slightly faster and consumes a little less memory in the Python reader, is slightly faster and consumes a little less memory in the Python
process. 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:: .. note::
When calling :meth:`~django.db.models.Model.save()` for instances with When calling :meth:`~django.db.models.Model.save()` for instances with
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment