def get_or_create(self, **kwargs):
        """
            Looks up an object with the given kwargs, creating one if necessary.
            Returns a tuple of (object, created), where created is a boolean
            specifying whether an object was created.
        """

        model = self.get(**kwargs)

        is_created = False

        if model is None:
            is_created = True
            model = self._model_class()

            for key, value in list(kwargs.items()):
                setattr(model, key, value)

        return model, is_created
def get_or_create ( self , ** kwargs ) : model = self . get ( ** kwargs ) is_created = False if model is None : is_created = True model = self . _model_class ( ) for key , value in list ( kwargs . items ( ) ) : setattr ( model , key , value ) return model , is_created
Looks up an object with the given kwargs, creating one if necessary.
            Returns a tuple of (object, created), where created is a boolean
            specifying whether an object was created.