def __init__(self, request_user, obj): self.obj = obj if self.obj is not None: obj_dict = ObjDict.from_obj(self.obj, request_user=request_user) self.str_fields = obj_dict.get_str_fields( ) if obj_dict.has_str_fields() else None else: self.str_fields = None if hasattr(self.obj, 'get_absolute_url') and callable( self.obj.get_absolute_url): if 'request_user' in inspect.signature( self.obj.get_absolute_url).parameters.keys(): self.url = self.obj.get_absolute_url(request_user=request_user) else: self.url = self.obj.get_absolute_url() self.desc = mark_safe(self.url.html) if hasattr( self.url, 'html') else getattr(self.url, 'text', None) else: self.url = None self.desc = None if self.desc is None: if self.str_fields is not None: # todo: use model_fields_verbose_names() to optionally populate verbose (localized) list keys. self.desc = print_list_group(self.str_fields) else: if self.obj is not None: self.desc = str(self.obj)
def __init__(self, obj): self.obj = obj self.str_fields = self.obj.get_str_fields() if hasattr( self.obj, 'get_str_fields') else None if hasattr(self.obj, 'get_absolute_url') and callable( self.obj.get_absolute_url): self.url = self.obj.get_absolute_url() self.desc = mark_safe(self.url.html) if hasattr( self.url, 'html') else getattr(self.url, 'text', None) else: self.url = None self.desc = None if self.desc is None: if self.str_fields is not None: # todo: use models.model_fields_verbose_names() to optionally populate verbose (localized) list keys. self.desc = print_list_group(self.str_fields) else: if self.obj is not None: self.desc = str(self.obj)