3 ms·
> I am not familiar with Python Object Model enough but, if your Python example still allocates an object with slots for all 47 other fields besides the three s
by Xzya 4y ago
> I am not familiar with Python Object Model enough but, if your Python example still allocates an object with slots for all 47 other fields besides the three selected, then you may still find yourself under circumstances you would rather have a "slim" version of the model and reduce memory allocation. This may be needed when you need to load dozens of thousands of entries into memory for processing or similar.
Alternatively you can also tell the ORM to return a dictionary rather than a model instance: https://docs.djangoproject.com/en/4.1/ref/models/querysets/#values https://docs.djangoproject.com/en/4.1/ref/models/querysets/#...
For example, you may get a list of dictionaries with only "field1", "field2" and "field3" from a model like this:
SomeModel.objects.filter(...).values("field1", "field2", "field3")
[{"field1": "foo", "field2": "bar", "field3": "baz"}]