当前位置: 首页>>代码示例>>Python>>正文


Python models.py方法代码示例

本文整理汇总了Python中django.db.models.py方法的典型用法代码示例。如果您正苦于以下问题:Python models.py方法的具体用法?Python models.py怎么用?Python models.py使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models的用法示例。


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

示例1: one_click_unsubscribe_link

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def one_click_unsubscribe_link(user_profile: UserProfile, email_type: str) -> str:
    """
    Generate a unique link that a logged-out user can visit to unsubscribe from
    Zulip e-mails without having to first log in.
    """
    return create_confirmation_link(user_profile,
                                    Confirmation.UNSUBSCRIBE,
                                    url_args = {'email_type': email_type})

# Functions related to links generated by the generate_realm_creation_link.py
# management command.
# Note that being validated here will just allow the user to access the create_realm
# form, where they will enter their email and go through the regular
# Confirmation.REALM_CREATION pathway.
# Arguably RealmCreationKey should just be another ConfirmationObjT and we should
# add another Confirmation.type for this; it's this way for historical reasons. 
开发者ID:zulip,项目名称:zulip,代码行数:18,代码来源:models.py

示例2: get_terminology_project

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def get_terminology_project(self, language_id):
        # FIXME: the code below currently uses the same approach to determine
        # the 'terminology' kind of a project as 'Project.is_terminology()',
        # which means it checks the value of 'checkstyle' field
        # (see pootle_project/models.py:240).
        #
        # This should probably be replaced in the future with a dedicated
        # project property.
        return self.get(language=language_id, project__checkstyle="terminology") 
开发者ID:evernote,项目名称:zing,代码行数:11,代码来源:models.py

示例3: post_save

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def post_save(self, instance, created, using=None, **kwargs):
        """
        The only difference between this method and the original is the first line, which omits a check to
        see if the object is newly created:
        https://github.com/treyhunner/django-simple-history/blob/2.7.2/simple_history/models.py#L456
        """
        if hasattr(instance, "skip_history_when_saving"):
            return
        if not kwargs.get("raw", False):  # pragma: no cover
            self.create_historical_record(instance, created and "+" or "~", using=using) 
开发者ID:edx,项目名称:ecommerce,代码行数:12,代码来源:models.py

示例4: post_delete

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def post_delete(self, instance, using=None, **kwargs):
        """
        The only difference between this method and the original is the addition of first line, which
        extends "skip_history_when_saving" checks to deletes:
        https://github.com/treyhunner/django-simple-history/blob/2.7.2/simple_history/models.py#L460
        """
        if hasattr(instance, "skip_history_when_saving"):
            return

        if self.cascade_delete_history:  # pragma: no cover
            manager = getattr(instance, self.manager_name)
            manager.using(using).all().delete()
        else:
            self.create_historical_record(instance, "-", using=using) 
开发者ID:edx,项目名称:ecommerce,代码行数:16,代码来源:models.py

示例5: __str__

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def __str__(self):
        return "%s the parking lot" % self.name


#
# Abstract base classes with related models where the sub-class has the
# same name in a different app and inherits from the same abstract base
# class.
# NOTE: The actual API tests for the following classes are in
#       model_inheritance_same_model_name/models.py - They are defined
#       here in order to have the name conflict between apps
# 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:models.py

示例6: test_models_py

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def test_models_py(self):
        """
        The models in the models.py file were loaded correctly.
        """
        self.assertEqual(apps.get_model("apps", "TotallyNormal"), TotallyNormal)
        with self.assertRaises(LookupError):
            apps.get_model("apps", "SoAlternative")

        with self.assertRaises(LookupError):
            new_apps.get_model("apps", "TotallyNormal")
        self.assertEqual(new_apps.get_model("apps", "SoAlternative"), SoAlternative) 
开发者ID:nesdis,项目名称:djongo,代码行数:13,代码来源:tests.py

示例7: test_explicit_path_overrides

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def test_explicit_path_overrides(self):
        """If path set as class attr, overrides __path__ and __file__."""
        class MyAppConfig(AppConfig):
            path = 'foo'

        ac = MyAppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py'))

        self.assertEqual(ac.path, 'foo') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py

示例8: test_dunder_path

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def test_dunder_path(self):
        """If single element in __path__, use it (in preference to __file__)."""
        ac = AppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py'))

        self.assertEqual(ac.path, 'a') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py

示例9: test_no_dunder_path_fallback_to_dunder_file

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def test_no_dunder_path_fallback_to_dunder_file(self):
        """If there is no __path__ attr, use __file__."""
        ac = AppConfig('label', Stub(__file__='b/__init__.py'))

        self.assertEqual(ac.path, 'b') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py

示例10: test_multiple_dunder_path_fallback_to_dunder_file

# 需要导入模块: from django.db import models [as 别名]
# 或者: from django.db.models import py [as 别名]
def test_multiple_dunder_path_fallback_to_dunder_file(self):
        """If the __path__ attr is length>1, use __file__ if set."""
        ac = AppConfig('label', Stub(__path__=['a', 'b'], __file__='c/__init__.py'))

        self.assertEqual(ac.path, 'c') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:tests.py


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