Django裡,model的資料操作與查詢,可進階寫成Manager,整個詳細過程記錄如下…
一、定義Manager class:
class TempleManager(models.Manager):
def create_temple(self,name,locateRegion,religiousBelief,masterGod,address,latitude,longitude,phone1,phone2):
temple = self.create(name = name, locateRegion = locateRegion, religiousBelief = religiousBelief, masterGod = masterGod, address = address, latitude = latitude, longitude = longitude, phone1 = phone1, phone2 = phone2)
return temple
def filter_temple(self,name,locateRegion,masterGod,address):
temple = self.filter(name = name, locateRegion = locateRegion, masterGod = masterGod, address = address)
return temple
def filterByMasterGod(self, masterGod):
temple = self.filter(masterGod = masterGod)
return temple
def filterByRegion(self, locateRegion):
temple = self.filter(locateRegion = locateRegion)
return temple