Django Model Optimization -


class model(models.model):    .......    .......    .......    .......    first_name = models.charfield(max_length = 50)    last_name = models.charfield(ma_lenghth = 50)     def full_name():       return '%s %s' %(self.first_name, self.last_name) 
  • calling models.objects.get().full_name() efficient

or

  • model.objects.filter().values('first_name, 'last_name') , adding string later better.

the question in regards database optimization. want know if calling method of model loads whole object or not. if not feel both result in same database operations if loads whole object values method better optimization.

please reply. share experiences if have on topic , statistics comparison if have one. please note example , not actual use case, model contains many other fields.

few feel using defer() or only() give desired result. found in django documentation prevents fields data being converted python object , not in sql look-ups. therefore don't think that's better. please me out in advance.

the question not whether "calling method of model loads whole object or not", because that's irrelevant. "loading of whole object" has been done get call. method operate on model object returned call, unless specify otherwise (using example defer or only) entire object.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -