Index: /branches/rel_avx_2_7_5/src/webui/webui/htdocs/new/src/hive/model/manager.py
===================================================================
--- /branches/rel_avx_2_7_5/src/webui/webui/htdocs/new/src/hive/model/manager.py	(revision 9137)
+++ /branches/rel_avx_2_7_5/src/webui/webui/htdocs/new/src/hive/model/manager.py	(working copy)
@@ -447,11 +447,11 @@
         assert field_name, "field_name must be specified"
 
         the_pk_dict = instance.pk_dict() or None
-            
+
         # for profile classes, the input pk_dict could be None or {}
         if hasattr(self, '_get_all_'+field_name):
             value = getattr(self, '_get_all_'+field_name)() #[{'pk_dict':xxx, '<field_name>':xxx}, ...]
-                
+
             # cannot call validate here because we don't have a instance to reference
             # so just call to_python
             try:
@@ -477,7 +477,7 @@
                 value = getattr(self, '_get_'+field_name)()
             else:
                 value = getattr(self, '_get_'+field_name)(the_pk_dict)
-                
+
             # cannot call validate here because we don't have a instance to reference
             # so just call to_python
             if not CACHE_SWITCH:
@@ -496,6 +496,23 @@
         else:
             custom_get_func = self._custom_gets.get(field_name, None)
             if custom_get_func:
+                field = instance._meta.get_field(field_name)
+                group = getattr(field, 'group', None)
+                if group and hasattr(self, '_get_' + group.name):
+                    need_query = False
+                    for f in group.fields:
+                        # Use instance.__dict__ to avoid triggering call function for each field(such as def get_xxx(self): ...)
+                        # If any field is DelayedQuery, it means this field doesn't have value yet
+                        val = instance.__dict__.get(f.attname, DelayedQuery)
+                        if val is DelayedQuery:
+                            need_query = True
+                            break
+                    if need_query:
+                        # if any field in the group is DelayedQuery, we need to call the _get_<group> function
+                        data = getattr(self, '_get_' + group.name)()
+                        for k, v in data.items():
+                            setattr(instance, k, v)
+                    return getattr(instance, field_name)
                 if the_pk_dict is None: # for profile only
                     rtn_dict = custom_get_func(self) # this is an unbound method, call with self
                 else:
@@ -525,7 +542,7 @@
                             if not rst and ins_pk == the_pk_dict:
                                 result = self._model._meta.get_field(field_name).to_python(each_rtn[field_name])
                                 return result
-                    
+
                 result = instance.get_attr_raw(field_name)
                 if result is DelayedQuery:
                     raise ManagerImplError('function _custom_gets for %s did not return value for instance:%s ' % (field_name, instance.pk_str()))
@@ -560,13 +577,13 @@
                         rtn.extend([dict_combine(x.pk_dict(), {'_asso_idx':idx}) for x in target_objs])
                     update_cache_field(instance, field_name, rtn)
                     return rtn
-            
+
         # come to here means there's not any custom implementation of "_get"
         # deligate to get(pk_dict)
         field = self._model._meta.get_field(field_name)
         #try:
         if field.group.isstats:
-            data = self._get_stats()        
+            data = self._get_stats()
             if CACHE_SWITCH:
                 if check_expire_all(self._model):
                     set_cache_all(self._model, data, stats=True)
@@ -584,7 +601,7 @@
                     if check_expire_all(self._model):
                         set_cache_all(self._model, data, config=True)
                     else:    
-                        update_cache_all(self._model, data, config=True)   
+                        update_cache_all(self._model, data, config=True)
                     the_instance = get_cache_one(self._model, the_pk_dict)
                     if not the_instance:
                         the_instance = get_cache_all(self._model).get(the_pk_dict)
@@ -602,7 +619,7 @@
                 if CACHE_SWITCH:
                     set_cache_one(the_instance)
                     the_instance = get_cache_one(self._model, the_pk_dict)
-            
+
         raw_value = the_instance.get_attr_raw(field_name)
         if raw_value is DelayedQuery:
             field = self._model._meta.get_field(field_name)
@@ -634,16 +651,16 @@
         return raw_value
         #except AttributeError as e:
         #    raise ManagerImplError('model %s has not implemented _get functions for field %s, case 2 with msg %s' % (self._model, field_name, e.message))
-    
+
     def get_pks(self):
-        return [e.pk_dict() for e in self.all()] 
-        
+        return [e.pk_dict() for e in self.all()]
+
     def get_stats_pks(self):
         try:
             return [e.pk_dict() for e in self.stats_all()]
         except ManagerImplError:
             return []
-        
+
     def clear(self):
         pass
 
