def default_category(cls): category = DBCategory.get_by_url("") if not category: category = DBCategory.create(url="", name="Home") category.save() _ = category.stats # init stats return cls(category)
def create_category(cls, **settings): url = cls.norm_url(settings.pop("url")) name = settings.pop("name") if cls.check_exist(url=url): raise Exception("category %s exist" % url) dbcategory = DBCategory.create(url=url, name=name) dbcategory.save() _ = dbcategory.stats # init stats dbcategory.update(**settings) return cls(dbcategory)