AttributeError: ‘QDateTime’ object has no attribute ‘upper’

Traceback (most recent call last):
File "D:\port\workspace\python\PyQtTest\hris\mdi00\querymodel.py", line 61, in data
return value.upper()
AttributeError: 'QDateTime' object has no attribute 'upper'

The code:

class CustomSqlModel(QSqlQueryModel):
  def data(self, index, role):
    value = super(CustomSqlModel, self).data(index, role)
    if value is not None and role == Qt.DisplayRole:
      if index.column() == 0:
        return '#%s' % value
      elif index.column() == 2:
        return value.upper()          

    if role == Qt.TextColorRole and index.column() == 1:
      return QColor(Qt.blue)

    return value

The problem is at line 8: “return value.upper()”.
I edit the class with adding function hasattr(value, ‘upper’),

class CustomSqlModel(QSqlQueryModel):
  def data(self, index, role):
    value = super(CustomSqlModel, self).data(index, role)
    if value is not None and role == Qt.DisplayRole:
      if index.column() == 0:
        return '#%s' % value
      elif index.column() == 2:
        if hasattr(value, 'upper'):
          return value.upper()

    if role == Qt.TextColorRole and index.column() == 1:
      return QColor(Qt.blue)

    return value
Advertisements