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

Python freezer.model_key函数代码示例

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

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



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

示例1: get_changes

 def get_changes(self):
     # Get the model defs so we can use them for the yield later
     model_defs = freeze_apps([self.migrations.app_label()])
     # Make the model changes
     for model_name in self.added_models:
         model = models.get_model(self.migrations.app_label(), model_name)
         real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
         yield ("AddModel", {
             "model": model,
             "model_def": real_fields,
         })
     # And the field changes
     for field_desc in self.added_fields:
         try:
             model_name, field_name = field_desc.split(".")
         except (TypeError, ValueError):
             raise ValueError("%r is not a valid field description." % field_desc)
         model = models.get_model(self.migrations.app_label(), model_name)
         real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
         yield ("AddField", {
             "model": model,
             "field": model._meta.get_field_by_name(field_name)[0],
             "field_def": real_fields[field_name],
         })
     # And the indexes
     for field_desc in self.added_indexes:
         try:
             model_name, field_name = field_desc.split(".")
         except (TypeError, ValueError):
             print("%r is not a valid field description." % field_desc)
         model = models.get_model(self.migrations.app_label(), model_name)
         yield ("AddIndex", {
             "model": model,
             "fields": [model._meta.get_field_by_name(field_name)[0]],
         })
开发者ID:adamjberg,项目名称:finna-be-octo-ninja,代码行数:35,代码来源:changes.py


示例2: forwards_code

 def forwards_code(self):
     
     return self.FORWARDS_TEMPLATE % {
         "model_name": self.model._meta.object_name,
         "field_name": self.field.name,
         "table_name": self.field.m2m_db_table(),
         "left_field": self.field.m2m_column_name()[:-3], # Remove the _id part
         "left_model_key": model_key(self.model),
         "right_field": self.field.m2m_reverse_name()[:-3], # Remove the _id part
         "right_model_key": model_key(self.field.rel.to),
     }
开发者ID:stevejalim,项目名称:djeeknights,代码行数:11,代码来源:actions.py


示例3: forwards_code

 def forwards_code(self):
     if isinstance(self.field, SortedManyToManyField) and self.field.sorted:
         return self.SORTED_FORWARDS_TEMPLATE % {
             "model_name": self.model._meta.object_name,
             "field_name": self.field.name,
             "table_name": self.field.m2m_db_table(),
             "left_field": self.field.m2m_column_name()[:-3], # Remove the _id part
             "left_column": self.field.m2m_column_name(),
             "left_model_key": model_key(self.model),
             "right_field": self.field.m2m_reverse_name()[:-3], # Remove the _id part
             "right_column": self.field.m2m_reverse_name(),
             "right_model_key": model_key(self.field.rel.to),
             "sort_field": self.field.sort_value_field_name,
         }
     else:
         return super(AddM2M, self).forwards_code()
开发者ID:richardbarran,项目名称:django-sortedm2m,代码行数:16,代码来源:fields.py


示例4: get_changes

    def get_changes(self):
        # Get the frozen models for this app
        model_defs = freeze_apps([self.migrations.app_label()])

        for model in models.get_models(models.get_app(self.migrations.app_label())):

            # Don't do anything for unmanaged, abstract or proxy models
            if model._meta.abstract or getattr(
                    model._meta, "proxy", False) or not getattr(model._meta, "managed", True):
                continue

            real_fields, meta, m2m_fields = self.split_model_def(
                model, model_defs[model_key(model)])

            # Firstly, add the main table and fields
            yield ("AddModel", {
                "model": model,
                "model_def": real_fields,
            })

            # Then, add any indexing/uniqueness that's around
            if meta:
                for attr, operation in (("unique_together", "AddUnique"),
                                        ("index_together", "AddIndex")):
                    together = eval(meta.get(attr, "[]"))
                    if together:
                        # If it's only a single tuple, make it into the longer one
                        if isinstance(together[0], string_types):
                            together = [together]
                        # For each combination, make an action for it
                        for fields in together:
                            yield (operation, {
                                "model": model,
                                "fields": [model._meta.get_field_by_name(x)[0] for x in fields],
                            })

            # Finally, see if there's some M2M action
            for name, triple in m2m_fields.items():
                field = model._meta.get_field_by_name(name)[0]
                # But only if it's not through=foo (#120)
                if field.rel.through:
                    try:
                        # Django 1.1 and below
                        through_model = field.rel.through_model
                    except AttributeError:
                        # Django 1.2
                        through_model = field.rel.through
                if (not field.rel.through) or getattr(through_model._meta, "auto_created", False):
                    yield ("AddM2M", {
                        "model": model,
                        "field": field,
                    })
开发者ID:Kayle009,项目名称:sentry,代码行数:52,代码来源:changes.py


示例5: get_changes

 def get_changes(self):
     # Get the model defs so we can use them for the yield later
     model_defs = freeze_apps([self.migrations.app_label()])
     # Make the model changes
     for model_name in self.added_models:
         model = models.get_model(self.migrations.app_label(), model_name)
         real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])
         yield ("AddModel", {
             "model": model,
             "model_def": real_fields,
         })
     # And the field changes
     for field_name in self.added_fields:
         raise NotImplementedError
     # And the indexes
     for index_name in self.added_indexes:
         raise NotImplementedError
开发者ID:stevejalim,项目名称:djeeknights,代码行数:17,代码来源:changes.py


示例6: get_changes

    def get_changes(self):
        # Get the frozen models for this app
        model_defs = freeze_apps([self.migrations.app_label()])

        for model in models.get_models(models.get_app(self.migrations.app_label())):

            # Don't do anything for unmanaged, abstract or proxy models
            if (
                model._meta.abstract
                or getattr(model._meta, "proxy", False)
                or not getattr(model._meta, "managed", True)
            ):
                continue

            real_fields, meta, m2m_fields = self.split_model_def(model, model_defs[model_key(model)])

            # Firstly, add the main table and fields
            yield ("AddModel", {"model": model, "model_def": real_fields})

            # Then, add any uniqueness that's around
            if meta:
                unique_together = eval(meta.get("unique_together", "[]"))
                if unique_together:
                    # If it's only a single tuple, make it into the longer one
                    if isinstance(unique_together[0], basestring):
                        unique_together = [unique_together]
                    # For each combination, make an action for it
                    for fields in unique_together:
                        yield (
                            "AddUnique",
                            {"model": model, "fields": [model._meta.get_field_by_name(x)[0] for x in fields]},
                        )

            # Finally, see if there's some M2M action
            for name, triple in m2m_fields.items():
                field = model._meta.get_field_by_name(name)[0]
                # But only if it's not through=foo (#120)
                if (not field.rel.through) or getattr(field.rel.through._meta, "auto_created", False):
                    yield ("AddM2M", {"model": model, "field": field})
开发者ID:johnarnfield,项目名称:django-south,代码行数:39,代码来源:changes.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python db.add_column函数代码示例发布时间:2022-05-27
下一篇:
Python freezer.freeze_apps函数代码示例发布时间: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