• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.base_concrete_model函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mezzanine.utils.models.base_concrete_model函数的典型用法代码示例。如果您正苦于以下问题:Python base_concrete_model函数的具体用法?Python base_concrete_model怎么用?Python base_concrete_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了base_concrete_model函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: save

 def save(self, update_site=False, *args, **kwargs):
     """
     Create a unique slug by appending an index. Set the site to
     the current site when the record is first created, unless the
     ``update_site`` argument is explicitly set to ``True``.
     """
     if not self.slug:
         # For custom content types, use the ``Page`` instance for
         # slug lookup.
         concrete_model = base_concrete_model(Slugged, self)
         self.slug = self.get_slug()
         i = 0
         while True:
             if i > 0:
                 if i > 1:
                     self.slug = self.slug.rsplit("-", 1)[0]
                 self.slug = "%s-%s" % (self.slug, i)
             qs = concrete_model.objects.all()
             if self.id is not None:
                 qs = qs.exclude(id=self.id)
             try:
                 qs.get(slug=self.slug)
             except ObjectDoesNotExist:
                 break
             i += 1
     if update_site or not self.id:
         self.site = Site.objects.get_current()
     super(Slugged, self).save(*args, **kwargs)
开发者ID:Vieceli,项目名称:mezzanine,代码行数:28,代码来源:models.py


示例2: set_content_model

 def set_content_model(self):
     """
     Set content_model to the child class's related name, or None if this is
     the base class.
     """
     is_base_class = (
         base_concrete_model(ContentTyped, self) == self.__class__)
     self.content_model = (
         None if is_base_class else self.get_content_model_name())
开发者ID:alan-hicks,项目名称:mezzanine,代码行数:9,代码来源:models.py


示例3: save

 def save(self, *args, **kwargs):
     """
     Set the initial ordering value.
     """
     if self._order is None:
         lookup = self.with_respect_to()
         concrete_model = base_concrete_model(Orderable, self)
         self._order = concrete_model.objects.filter(**lookup).count()
     super(Orderable, self).save(*args, **kwargs)
开发者ID:cmarrero,项目名称:mezzanine,代码行数:9,代码来源:models.py


示例4: delete

 def delete(self, *args, **kwargs):
     """
     Update the ordering values for siblings.
     """
     lookup = self.with_respect_to()
     lookup["_order__gte"] = self._order
     concrete_model = base_concrete_model(Orderable, self)
     after = concrete_model.objects.filter(**lookup)
     after.update(_order=models.F("_order") - 1)
     super(Orderable, self).delete(*args, **kwargs)
开发者ID:Vieceli,项目名称:mezzanine,代码行数:10,代码来源:models.py


示例5: generate_unique_slug

 def generate_unique_slug(self):
     """
     Create a unique slug by passing the result of get_slug() to
     utils.urls.unique_slug, which appends an index if necessary.
     """
     # For custom content types, use the ``Page`` instance for
     # slug lookup.
     concrete_model = base_concrete_model(Slugged, self)
     slug_qs = concrete_model.objects.exclude(id=self.id)
     return unique_slug(slug_qs, "slug", self.get_slug())
开发者ID:JPWKU,项目名称:mezzanine,代码行数:10,代码来源:models.py


示例6: adjacent_by_order

 def adjacent_by_order(self, direction):
     """
     Retrieves next object by order in the given direction.
     """
     lookup = self.with_respect_to()
     lookup["_order"] = self._order + direction
     concrete_model = base_concrete_model(Orderable, self)
     try:
         return concrete_model.objects.get(**lookup)
     except concrete_model.DoesNotExist:
         pass
开发者ID:422053362,项目名称:mezzanine,代码行数:11,代码来源:models.py


示例7: save

 def save(self, *args, **kwargs):
     """
     Create a unique slug by appending an index.
     """
     if not self.slug:
         self.slug = self.get_slug()
     # For custom content types, use the ``Page`` instance for
     # slug lookup.
     concrete_model = base_concrete_model(Slugged, self)
     slug_qs = concrete_model.objects.exclude(id=self.id)
     self.slug = unique_slug(slug_qs, "slug", self.slug)
     super(Slugged, self).save(*args, **kwargs)
开发者ID:PythonCharmers,项目名称:mezzanine,代码行数:12,代码来源:models.py


示例8: _get_next_or_previous_by_order

 def _get_next_or_previous_by_order(self, is_next, **kwargs):
     """
     Retrieves next or previous object by order. We implement our
     own version instead of Django's so we can hook into the
     published manager, concrete subclasses and our custom
     ``with_respect_to`` method.
     """
     lookup = self.with_respect_to()
     lookup["_order"] = self._order + (1 if is_next else -1)
     concrete_model = base_concrete_model(Orderable, self)
     try:
         queryset = concrete_model.objects.published
     except AttributeError:
         queryset = concrete_model.objects.filter
     try:
         return queryset(**kwargs).get(**lookup)
     except concrete_model.DoesNotExist:
         pass
开发者ID:JPWKU,项目名称:mezzanine,代码行数:18,代码来源:models.py


示例9: _get_next_or_previous_by_publish_date

 def _get_next_or_previous_by_publish_date(self, is_next, **kwargs):
     """
     Retrieves next or previous object by publish date. We implement
     our own version instead of Django's so we can hook into the
     published manager and concrete subclasses.
     """
     arg = "publish_date__gt" if is_next else "publish_date__lt"
     order = "publish_date" if is_next else "-publish_date"
     lookup = {arg: self.publish_date}
     concrete_model = base_concrete_model(Displayable, self)
     try:
         queryset = concrete_model.objects.published
     except AttributeError:
         queryset = concrete_model.objects.all
     try:
         return queryset(**kwargs).filter(**lookup).order_by(order)[0]
     except IndexError:
         pass
开发者ID:JPWKU,项目名称:mezzanine,代码行数:18,代码来源:models.py


示例10: __init__

    def __init__(self, *args, **kwargs):
        """
        For subclasses that are registered with an Admin class
        that doesn't implement fieldsets, add any extra model fields
        to this instance's fieldsets. This mimics Django's behaviour of
        adding all model fields when no fieldsets are defined on the
        Admin class.
        """
        super(ContentTypedAdmin, self).__init__(*args, **kwargs)

        self.concrete_model = base_concrete_model(ContentTyped, self.model)

        # Test that the fieldsets don't differ from the concrete admin's.
        if (self.model is not self.concrete_model and
                self.fieldsets == self.base_concrete_modeladmin.fieldsets):

            # Make a copy so that we aren't modifying other Admin
            # classes' fieldsets.
            self.fieldsets = deepcopy(self.fieldsets)

            # Insert each field between the publishing fields and nav
            # fields. Do so in reverse order to retain the order of
            # the model's fields.
            model_fields = self.concrete_model._meta.get_fields()
            concrete_field = '{concrete_model}_ptr'.format(
                concrete_model=self.concrete_model.get_content_model_name())
            exclude_fields = [f.name for f in model_fields] + [concrete_field]

            try:
                exclude_fields.extend(self.exclude)
            except (AttributeError, TypeError):
                pass

            try:
                exclude_fields.extend(self.form.Meta.exclude)
            except (AttributeError, TypeError):
                pass

            fields = self.model._meta.fields + self.model._meta.many_to_many
            for field in reversed(fields):
                if field.name not in exclude_fields and field.editable:
                    if not hasattr(field, "translated_field"):
                        self.fieldsets[0][1]["fields"].insert(3, field.name)
开发者ID:christianwgd,项目名称:mezzanine,代码行数:43,代码来源:admin.py


示例11: save

 def save(self, *args, **kwargs):
     """
     Create a unique slug by appending an index.
     """
     if not self.slug:
         self.slug = self.get_slug()
     # For custom content types, use the ``Page`` instance for
     # slug lookup.
     concrete_model = base_concrete_model(Slugged, self)
     i = 0
     while True:
         if i > 0:
             if i > 1:
                 self.slug = self.slug.rsplit("-", 1)[0]
             self.slug = "%s-%s" % (self.slug, i)
         qs = concrete_model.objects.all()
         if self.id is not None:
             qs = qs.exclude(id=self.id)
         try:
             qs.get(slug=self.slug)
         except ObjectDoesNotExist:
             break
         i += 1
     super(Slugged, self).save(*args, **kwargs)
开发者ID:31H0B1eV,项目名称:mezzanine,代码行数:24,代码来源:models.py


示例12: get_content_models

 def get_content_models(cls):
     """ Return all subclasses of the concrete model.  """
     concrete_model = base_concrete_model(ContentTyped, cls)
     return [m for m in apps.get_models()
             if m is not concrete_model and issubclass(m, concrete_model)]
开发者ID:alan-hicks,项目名称:mezzanine,代码行数:5,代码来源:models.py



注:本文中的mezzanine.utils.models.base_concrete_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.get_user_model函数代码示例发布时间:2022-05-27
下一篇:
Python importing.path_for_import函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap