Manager
Your code needs to be in a file named
manager.pyor folder namedmanagerinside your Application.
Info
The purpose of the manager is to handle updates to the database
File or Folder Layout
Tool
fastberry.manager
Python Code
manager.py
# -*- coding: utf-8 -*-
"""
{ Controller } for the Database(s)
"""
import fastberry as fb
from . import types
class Base:
"""Reusable Manager"""
@classmethod
async def all(cls):
return await cls.objects.all()
@classmethod
async def reset_table(cls):
return await cls.objects.delete(None, all=True)
@fb.manager
class Product(Base):
"""Product Manager"""
model = types.Product
@classmethod
async def create(cls, form):
results = None
if form.is_valid:
results = await cls.objects.create(form.data.__dict__)
return results
__init__.py
# -*- coding: utf-8 -*-
"""
Manager - Init
"""
# Import your <managers> here.
from .product import Product
product.py
# -*- coding: utf-8 -*-
"""
{ Controller } for the Database(s)
"""
import fastberry as fb
from . import types
class Base:
"""Reusable Manager"""
@classmethod
async def all(cls):
return await cls.objects.all()
@classmethod
async def reset_table(cls):
return await cls.objects.delete(None, all=True)
@fb.manager
class Product(Base):
"""Product Manager"""
model = types.Product
@classmethod
async def create(cls, form):
results = None
if form.is_valid:
results = await cls.objects.create(form.data.__dict__)
return results