コード例 #1
0
ファイル: test_basic.py プロジェクト: idlesign/django-etc
    def test_from_string(self):
        cl = get_model_class_from_string('auth.User')
        assert cl is User

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('some')

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('etc.InheritedModel')
コード例 #2
0
ファイル: test_basic.py プロジェクト: vcostas/education
    def test_from_string(self):
        cl = get_model_class_from_string('auth.User')
        assert cl is User

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('some')

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('etc.InheritedModel')
コード例 #3
0
ファイル: models.py プロジェクト: idlesign/django-siteflags
    def get_flags_for_objects(cls, objects_list, user=None, status=None):
        """Returns a dictionary with flag objects associated with the given model objects.
        The dictionary is indexed by objects IDs.
        Each dict entry contains a list of associated flag objects.

        :param list, QuerySet objects_list:
        :param User user:
        :param int status:
        :rtype: dict
        """
        return get_model_class_from_string(MODEL_FLAG).get_flags_for_objects(objects_list, user=user, status=status)
コード例 #4
0
ファイル: models.py プロジェクト: idlesign/django-siteflags
    def get_flags_for_types(cls, mdl_classes, user=None, status=None, allow_empty=True):
        """Returns a dictionary with flag objects associated with the given model classes (types).
        The dictionary is indexed by model classes.
        Each dict entry contains a list of associated flag objects.

        :param list mdl_classes:
        :param User user:
        :param int status:
        :param bool allow_empty: Flag. Include results for all given types, even those without associated flags.
        :rtype: dict
        """
        return get_model_class_from_string(MODEL_FLAG).get_flags_for_types(
            mdl_classes, user=user, status=status, allow_empty=allow_empty)
コード例 #5
0
ファイル: utils.py プロジェクト: phoebebright/django-sitecats
def get_tie_model():
    """Returns the Tie model, set for the project."""
    return get_model_class_from_string(MODEL_TIE)
コード例 #6
0
ファイル: utils.py プロジェクト: phoebebright/django-sitecats
def get_category_model():
    """Returns the Category model, set for the project."""
    return get_model_class_from_string(MODEL_CATEGORY)
コード例 #7
0
ファイル: models.py プロジェクト: Asgardian8740/Portfolio_new
 def hit_count(self):
     ctype = ContentType.objects.get_for_model(self.__class__)
     hit_count, created = get_model_class_from_string(
         MODEL_HITCOUNT).objects.get_or_create(content_type=ctype,
                                               object_pk=self.pk)
     return hit_count
コード例 #8
0
def get_tie_model() -> Type['TieBase']:
    """Returns the Tie model, set for the project."""
    return get_model_class_from_string(MODEL_TIE)
コード例 #9
0
def get_category_model() -> Type['CategoryBase']:
    """Returns the Category model, set for the project."""
    return get_model_class_from_string(MODEL_CATEGORY)