class CakeManager(Manager): #自定义对象管理器
def create_cake(self, name, price, color):
cake = self.model()
cake.name = name
cake.price = price
cake.color = color
cake.save()
return cake
class Cake(models.Model):
name = models.CharField(max_length=20)
price = models.FloatField()
color = models.CharField(max_length=20)
# 关联自定义对象管理器
cakemanager = CakeManager()