本文整理汇总了Python中django.db.models.fields.related.ForeignKey.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ForeignKey.__init__方法的具体用法?Python ForeignKey.__init__怎么用?Python ForeignKey.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.fields.related.ForeignKey
的用法示例。
在下文中一共展示了ForeignKey.__init__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, chained_field=None, chained_model_field=None, show_all=False, auto_choose=False, **kwargs):
if isinstance(to, basestring):
self.app_name, self.model_name = to.split('.')
else:
self.app_name = to._meta.app_label
self.model_name = to._meta.object_name
self.chain_field = chained_field
self.model_field = chained_model_field
self.show_all = show_all
self.auto_choose = auto_choose
ForeignKey.__init__(self, to, **kwargs)
示例2: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, address_field=None, **kwargs):
if isinstance(to, six.string_types):
self.app_name, self.model_name = to.split('.')
else:
self.app_name = to._meta.app_label
self.model_name = to._meta.object_name
self.address_field = address_field
kwargs.setdefault('blank', True)
kwargs.setdefault('null', True)
ForeignKey.__init__(self, to, **kwargs)
示例3: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, chained_field=None, chained_model_field=None,
show_all=False, auto_choose=False, view_name=None, exclude_self=None, **kwargs):
if isinstance(to, basestring):
self.app_name, self.model_name = to.split('.')
else:
self.app_name = to._meta.app_label
self.model_name = to._meta.object_name
self.chain_field = chained_field
self.model_field = chained_model_field
self.show_all = show_all
self.auto_choose = auto_choose
self.view_name = view_name
ForeignKey.__init__(self, to, **kwargs)
self.exclude_self = exclude_self
#TODO: clean-up
if exclude_self:
self.exclude_self = exclude_self
示例4: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, chained_field=None, chained_model_field=None,
show_all=False, auto_choose=False, view_name=None, **kwargs):
"""
examples:
class Continent(models.Model):
name = models.CharField(max_length=255)
class Country(models.Model):
continent = models.ForeignKey(Continent)
class Location(models.Model):
continent = models.ForeignKey(Continent)
country = ChainedForeignKey(
Country,
chained_field="continent",
chained_model_field="continent",
show_all=True,
auto_choose=True,
# limit_choices_to={'name':'test'}
)
``chained_field`` is the name of the ForeignKey field referenced by ChainedForeignKey of the same Model.
in the examples, chained_field is the name of field continent in Model Location.
``chained_model_field`` is the name of the ForeignKey field referenced in the 'to' Model.
in the examples, chained_model_field is the name of field continent in Model Country.
``show_all`` controls whether show other choices below the filtered choices, with separater '----------'.
``auto_choose`` controls whether auto select the choice when there is only one available choice.
``view_name`` controls which view to use, 'chained_filter' or 'chained_filter_all'.
"""
if isinstance(to, six.string_types):
self.to_app_name, self.to_model_name = to.split('.')
else:
self.to_app_name = to._meta.app_label
self.to_model_name = to._meta.object_name
self.chained_field = chained_field
self.chained_model_field = chained_model_field
self.show_all = show_all
self.auto_choose = auto_choose
self.view_name = view_name
ForeignKey.__init__(self, to, **kwargs)
示例5: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, group_field, **kwargs):
self.group_field = group_field
self._choices = True
ForeignKey.__init__(self, to, **kwargs)
示例6: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to='fias.AddrObj', **kwargs):
kwargs.setdefault('related_name', '+')
ForeignKey.__init__(self, to, **kwargs)
示例7: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, translated_field, language, to, to_field=None, *args,
**kwargs):
self._related_pre_init(translated_field, language, *args, **kwargs)
ForeignKey.__init__(self, to, to_field, **kwargs)
self._related_post_init()
示例8: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, chained_field, chained_model_field, *args, **kwargs):
self.app_name = to._meta.app_label
self.model_name = to._meta.object_name
self.chain_field = chained_field
self.model_field = chained_model_field
ForeignKey.__init__(self, to, *args, **kwargs)
示例9: __init__
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import __init__ [as 别名]
def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs):
ForeignKey.__init__(self, to, to_field=to_field, rel_class=rel_class, **kwargs)
self.on_delete = DO_NOTHING