Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        # check this is not abstract model otherwise stop creating instance of this model
        if self._meta.abstract:
            raise AbstractNotInstantiate(f'Can not instantiate abstract model "{self.__class__.__name__}"')

        # Allow users to set fields values direct from the constructor method
        for k, v in kwargs.items():
            setattr(self, k, v)
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        # check this is not abstract model otherwise stop creating instance of this model
        if self._meta.abstract:
            raise AbstractNotInstantiate(
                f'Can not instantiate abstract model "{self.__class__.__name__}"'
            )

        # Allow users to set fields values direct from the constructor method
        for k, v in kwargs.items():
            setattr(self, k, v)

        # Create instance for nested model
        # for direct assignment to nested model
        for f in self._meta.field_list.values():
            if isinstance(f, fields.NestedModel):
                setattr(self, f.name, f.nested_model())