當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。