difference between values() and only()

Assuming Blabla has the fields in your question, as well as field4,

Blabla.objects.only('field1', 'field2', 'field3')[0].field4

will return the value of that object’s field4 (with a new database query to retrieve that info), whereas

Blabla.objects.values('field1', 'field2', 'field3')[0].field4

will give

AttributeError: 'dict' object has no attribute 'field4'

This is because .values() returns a QuerySet that returns dictionaries, which is essentially a list of dicts, rather than model instances (Blabla).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)