我有一个objectlistview。我从中删除了一行,然后我想更新列表而不删除该行。我用数据库中的数据填充列表。我尝试重新填充列表,但后来它似乎使用了列表中已有的数据。
我想我可以用 clearAll(清除列表(来解决它,然后添加对象并再次添加数据库。但似乎应该可以只更新列表。这是我的代码:
def deletemeas(self):
MAid = self.objectma.id
MAname = self.pagename
objectsRemList = self.tempmeasurements.GetCheckedObjects()
print 'objectremlist', objectsRemList
for measurement in objectsRemList:
print measurement
Measname = measurement.filename
Measid = database.Measurement.select(database.Measurement.q.filename == Measname)[0].id
deleteMeas = []
deleteMeas.append(MAid)
deleteMeas.append(Measid)
pub.sendMessage('DELETE_MEAS', Container(data=deleteMeas)) #to microanalyse controller
#here I get the latest information from the database what should be viewed in the objectlist self.tempmeasurements
MeasInListFromDB = list(database.Microanalysismeasurement.select(database.Microanalysismeasurement.q.microanalysisid == MAid))
print 'lijstmetingen:', MeasInListFromDB
#this doesn't work
self.tempmeasurements.RefreshObjects(MeasInListFromDB)
好吧,这实际上比我想象的要容易......
我添加了这一行:
self.tempmeasurements.RemoveObject(measurement)
因此,我首先从数据库表中删除了数据,然后删除了对象列表视图中的行。