當前位置: 首頁>>代碼示例>>Python>>正文


Python models.ContentType方法代碼示例

本文整理匯總了Python中django.contrib.contenttypes.models.ContentType方法的典型用法代碼示例。如果您正苦於以下問題:Python models.ContentType方法的具體用法?Python models.ContentType怎麽用?Python models.ContentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.contrib.contenttypes.models的用法示例。


在下文中一共展示了models.ContentType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: settings

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def settings(self):
        if self.cached_settings:
            return self.cached_settings
        else:
            from django.conf import settings
            allowed_configurations = {
                'CONTENT_TYPE_CLASS': ContentType,
                'USER_CLASS': settings.AUTH_USER_MODEL,
                'PERMISSION_CLASS': Permission,
                'GROUP_CLASS': Group,
                'INJECT_MODEL_ADMIN': False
            }
            river_settings = {}
            for key, default in allowed_configurations.items():
                river_settings[key] = getattr(settings, self.get_with_prefix(key), default)

            river_settings['IS_MSSQL'] = connection.vendor == 'microsoft'
            self.cached_settings = river_settings

            return self.cached_settings 
開發者ID:javrasya,項目名稱:django-river,代碼行數:22,代碼來源:config.py

示例2: add_view_permissions

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def add_view_permissions(sender, **kwargs):
    """
    This syncdb hooks takes care of adding a view permission too all our
    content types.
    """
    # for each of our content types
    for content_type in ContentType.objects.all():
        # build our permission slug
        codename = "view_%s" % content_type.model

        # if it doesn't exist..
        if not Permission.objects.filter(content_type=content_type, codename=codename):
            # add it
            Permission.objects.create(content_type=content_type,
                                      codename=codename,
                                      name="Can view %s" % content_type.name)
            #print "Added view permission for %s" % content_type.name

# check for all our view permissions after a syncdb 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:21,代碼來源:models.py

示例3: check_dependencies

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def check_dependencies(self):
        """
        Check that all things needed to run the admin have been correctly installed.

        The default implementation checks that LogEntry, ContentType and the
        auth context processor are installed.
        """
        from django.contrib.contenttypes.models import ContentType

        if not ContentType._meta.installed:
            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in "
                                       "your INSTALLED_APPS setting in order to use the admin application.")

        default_template_engine = Engine.get_default()
        if not ('django.contrib.auth.context_processors.auth' in default_template_engine.context_processors or
                'django.core.context_processors.auth' in default_template_engine.context_processors):
            raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' "
                                       "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.") 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:20,代碼來源:sites.py

示例4: __init__

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def __init__(self, data=None, files=None, instance=None, save_as_new=None,
                 prefix=None, queryset=None, **kwargs):
        opts = self.model._meta
        self.instance = instance
        self.rel_name = '-'.join((
            opts.app_label, opts.model_name,
            self.ct_field.name, self.ct_fk_field.name,
        ))
        if self.instance is None or self.instance.pk is None:
            qs = self.model._default_manager.none()
        else:
            if queryset is None:
                queryset = self.model._default_manager
            qs = queryset.filter(**{
                self.ct_field.name: ContentType.objects.get_for_model(
                    self.instance, for_concrete_model=self.for_concrete_model),
                self.ct_fk_field.name: self.instance.pk,
            })
        super(BaseGenericInlineFormSet, self).__init__(
            queryset=qs, data=data, files=files,
            prefix=prefix,
            **kwargs
        ) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:25,代碼來源:forms.py

示例5: define_relationship

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def define_relationship(name, from_model, to_model):
    if name in _relationship_registry:
        raise KeyError(name)
    
    _from_ctype = from_model
    _to_ctype = to_model
    
    if isinstance(_from_ctype, str):
        _from_ctype = get_model(_from_ctype)
    if isinstance(_to_ctype, str):
        _to_ctype = get_model(_to_ctype)
    
    if not isinstance(_from_ctype, ContentType):
        _from_ctype = ContentType.objects.get_for_model(_from_ctype)
    if not isinstance(_to_ctype, ContentType):
        _to_ctype = ContentType.objects.get_for_model(_to_ctype)
    
    relationship = Relationship(name=name,
                                from_content_type=_from_ctype,
                                to_content_type=_to_ctype)
    
    _relationship_registry[name] = relationship
    return relationship 
開發者ID:dfunckt,項目名稱:django-connections,代碼行數:25,代碼來源:models.py

示例6: translations_objects

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def translations_objects(self, lang):
        """
        Return the complete list of translation objects of a Translatable
        instance

        @type lang: string
        @param lang: a string with the name of the language

        @rtype: list of Translation
        @return: Returns a list of translations objects
        """
        return Translation.objects.filter(
            object_id=self.id,
            content_type=ContentType.objects.get_for_model(self),
            lang=lang
        ) 
開發者ID:angvp,項目名稱:django-klingon,代碼行數:18,代碼來源:models.py

示例7: translations_link

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def translations_link(self):
        """
        Print on admin change list the link to see all translations for this object

        @type text: string
        @param text: a string with the html to link to the translations admin interface
        """
        translation_type = ContentType.objects.get_for_model(Translation)
        link = urlresolvers.reverse('admin:%s_%s_changelist' % (
            translation_type.app_label,
            translation_type.model),
        )

        object_type = ContentType.objects.get_for_model(self)
        link += '?content_type__id__exact=%s&object_id=%s' % (object_type.id, self.id)
        return '<a href="%s">translate</a>' % link 
開發者ID:angvp,項目名稱:django-klingon,代碼行數:18,代碼來源:models.py

示例8: add_view_permissions

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def add_view_permissions(sender, **kwargs):
    """
    This syncdb hooks takes care of adding a view permission too all our
    content types.
    """
    # for each of our content types
    for content_type in ContentType.objects.all():
        # build our permission slug
        codename = "view_%s" % content_type.model

        # if it doesn't exist..
        if not Permission.objects.filter(content_type=content_type, codename=codename):
            # add it
            Permission.objects.create(content_type=content_type,
                                      codename=codename,
                                      name="Can view %s" % content_type.name)
            # print "Added view permission for %s" % content_type.name

# check for all our view permissions after a syncdb 
開發者ID:Superbsco,項目名稱:weibo-analysis-system,代碼行數:21,代碼來源:models.py

示例9: flatten_objects

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def flatten_objects(inobj, key_was=None):
    if isinstance(inobj, dict):
        return {k: flatten_objects(v, key_was=k) for k, v in inobj.items()}
    elif isinstance(inobj, (tuple, list)):
        return [flatten_objects(v) for v in inobj]
    elif isinstance(inobj, datetime.datetime):
        return inobj.strftime("%Y-%m-%d %H:%M:%S %Z")
    elif isinstance(inobj, datetime.date):
        return inobj.strftime("%Y-%m-%d")
    elif isinstance(inobj, uuid.UUID):
        return str(inobj)
    elif isinstance(inobj, decimal.Decimal) or (
        key_was == "amount" and isinstance(inobj, (int, float))
    ):
        return "{:.2f}".format(inobj)
    else:
        try:
            content_type = ContentType.objects.get_for_model(type(inobj))
            return {
                "object": content_type.name,
                "ref": (content_type.app_label, content_type.model, inobj.pk),
                "value": str(inobj),
            }
        except Exception:
            return str(inobj) 
開發者ID:byro,項目名稱:byro,代碼行數:27,代碼來源:log.py

示例10: toggle_collection_nav

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def toggle_collection_nav(cls, issue_type):
        """Toggles a nav item for the given issue_type
        :param `journal.models.IssueType` issue_type: The issue type to toggle
        """

        defaults = {
            "link_name": issue_type.plural_name,
            "link": "/collections/%s" % (issue_type.code),
        }
        content_type = ContentType.objects.get_for_model(issue_type.journal)

        nav, created = cls.objects.get_or_create(
            content_type=content_type,
            object_id=issue_type.pk,
            defaults=defaults,
        )

        if not created:
            nav.delete() 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:21,代碼來源:models.py

示例11: __init__

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def __init__(self, app_name: str, model_name: Optional[str] = None, content_type_field: str = 'content_type',
                 id_field: str = 'object_id'):
        """

        :param app_name: The name of the app or `<app_name>.<model_name>`
        :param model_name: The name of the model with GenericRelation
        :param content_type_field: The name of the FK to ContentType Model
        :param id_field: The id of the related model
        """
        if model_name is None:
            self.app_name, self.model_name = app_name.split('.')
        else:
            self.app_name = app_name
            self.model_name = model_name
        self.content_type_field = content_type_field
        self.id_field = id_field

        super().__init__() 
開發者ID:druids,項目名稱:django-GDPR,代碼行數:20,代碼來源:generic_relation.py

示例12: test_specific_gracefully_handles_missing_rows

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def test_specific_gracefully_handles_missing_rows(self):
        # 5928 - PageQuerySet.specific should gracefully handle pages whose ContentType
        # row in the specific table no longer exists

        # Trick specific_iterator into always looking for EventPages
        with mock.patch(
            'wagtail.core.query.ContentType.objects.get_for_id',
            return_value=ContentType.objects.get_for_model(EventPage),
        ):
            with self.assertWarnsRegex(RuntimeWarning, "Specific versions of the following pages could not be found"):
                pages = list(Page.objects.get(url_path='/home/').get_children().specific())

            # All missing pages should be supplemented with generic pages
            self.assertEqual(pages, [
                Page.objects.get(url_path='/home/events/'),
                Page.objects.get(url_path='/home/about-us/'),
                Page.objects.get(url_path='/home/other/'),
            ]) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:20,代碼來源:test_page_queryset.py

示例13: page_view_received

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def page_view_received(sender, **kwargs):
	kwargs.pop('signal', None)
	page_path = kwargs.pop('page_path')
	primary_obj = kwargs.pop('primary_obj', None)
	secondary_obj = kwargs.pop('secondary_obj', None)
	print secondary_obj
	user = sender
	if not user.is_authenticated():
		new_page_view = PageView.objects.create(path=page_path, timestamp=timezone.now())
	else:
		new_page_view = PageView.objects.create(path=page_path, user=user, timestamp=timezone.now())
	if primary_obj:
		new_page_view.primary_object_id = primary_obj.id
		new_page_view.primary_content_type = ContentType.objects.get_for_model(primary_obj)
		new_page_view.save()
	if secondary_obj:
		new_page_view.secondary_object_id = secondary_obj.id
		new_page_view.secondary_content_type = ContentType.objects.get_for_model(secondary_obj)
		new_page_view.save() 
開發者ID:codingforentrepreneurs,項目名稱:srvup-rest-framework,代碼行數:21,代碼來源:models.py

示例14: restrict

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def restrict(self):
        # method restricts all objects down by restriction hierarchy
        if self.restriction != self:
            current_restriction_id = self.restriction_id
            current_restriction_ctype_id = self.restriction_content_type_id
            self.restriction = self
            if self.pk is not None:
                ctype_dict = self.get_restriction_descendants()
                for ctype_id, object_ids in ctype_dict.items():
                    ctype = ContentType.objects.get_for_id(ctype_id)
                    objs = ctype.model_class().objects.filter(
                        pk__in=object_ids, restriction_id=current_restriction_id,
                        restriction_content_type_id=current_restriction_ctype_id
                    )
                    objs.update(
                        restriction_id=self.id,
                        restriction_content_type=ContentType.objects.get_for_model(self)
                    )
            self.save() 
開發者ID:grey0ne,項目名稱:django-protector,代碼行數:21,代碼來源:models.py

示例15: unrestrict

# 需要導入模塊: from django.contrib.contenttypes import models [as 別名]
# 或者: from django.contrib.contenttypes.models import ContentType [as 別名]
def unrestrict(self):
        if self.restriction is None:
            return
        ctype_dict = self.get_restriction_descendants()
        current_restriction_id = self.restriction_id
        current_restriction_ctype_id = self.restriction_content_type_id
        for ctype_id, object_ids in ctype_dict.items():
            ctype = ContentType.objects.get_for_id(ctype_id)
            objs = ctype.model_class().objects.filter(
                pk__in=object_ids, restriction_id=current_restriction_id,
                restriction_content_type_id=current_restriction_ctype_id
            )
            # take only objects that restricted by same object as self
            objs.update(
                restriction_id=None,
                restriction_content_type=None
            )
        self.restriction = None
        self.save() 
開發者ID:grey0ne,項目名稱:django-protector,代碼行數:21,代碼來源:models.py


注:本文中的django.contrib.contenttypes.models.ContentType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。