<reponame>PhilipWafula/faulu-apis-demo
import random
import string

from app.server import db
from app.server.utils.models import BaseModel


class Organization(BaseModel):
    """
    Creates an organization
    """

    __tablename__ = "organizations"

    # attributes
    name = db.Column(db.String(100))
    is_master = db.Column(db.Boolean, default=False, index=True)
    public_identifier = db.Column(db.String(8), nullable=False, index=True, unique=True)
    address = db.Column(db.String, nullable=True)

    users = db.relationship("User", backref="organization")

    @staticmethod
    def master_organisation() -> "Organization":
        return Organization.query.filter_by(is_master=True).first()

    def __init__(self, public_identifier=None, **kwargs):
        super(Organization, self).__init__(**kwargs)
        components = string.ascii_letters + string.digits
        identifier = "".join(random.choice(components) for i in range(8))
        self.public_identifier = public_identifier or identifier

import random
import string

from app.server import db
from app.server.utils.models import BaseModel


class Organization(BaseModel):
    """
    Creates an organization
    """

    __tablename__ = "organizations"

    # attributes
    name = db.Column(db.String(100))
    is_master = db.Column(db.Boolean, default=False, index=True)
    public_identifier = db.Column(db.String(8), nullable=False, index=True, unique=True)
    address = db.Column(db.String, nullable=True)

    users = db.relationship("User", backref="organization")

    @staticmethod
    def master_organisation() -> "Organization":
        return Organization.query.filter_by(is_master=True).first()

    def __init__(self, public_identifier=None, **kwargs):
        super(Organization, self).__init__(**kwargs)
        components = string.ascii_letters + string.digits
        identifier = "".join(random.choice(components) for i in range(8))
        self.public_identifier = public_identifier or identifier
Creates an organization # attributes