本文整理汇总了Python中django.db.models.fields.related.ManyToManyField.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ManyToManyField.__init__方法的具体用法?Python ManyToManyField.__init__怎么用?Python ManyToManyField.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.fields.related.ManyToManyField
的用法示例。
在下文中一共展示了ManyToManyField.__init__方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.db.models.fields.related import ManyToManyField [as 别名]
# 或者: from django.db.models.fields.related.ManyToManyField import __init__ [as 别名]
def __init__(self, to, chained_field=None, chained_model_field=None,
show_all=False, auto_choose=False, view_name=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
ManyToManyField.__init__(self, to, **kwargs)
示例2: __init__
# 需要导入模块: from django.db.models.fields.related import ManyToManyField [as 别名]
# 或者: from django.db.models.fields.related.ManyToManyField import __init__ [as 别名]
def __init__(self, to, **kwargs):
ManyToManyFieldOriginal.__init__(to, **kwargs)
self.model = None
self.query_field_name = ''
self.core_filters = {}
self.instance = None
self.symmetrical = None
self.source_field = None
self.source_field_name = ''
self.target_field_name = ''
self.reverse = None
self.through = None
self.prefetch_cache_name = None
self.related_val = None
示例3: __init__
# 需要导入模块: from django.db.models.fields.related import ManyToManyField [as 别名]
# 或者: from django.db.models.fields.related.ManyToManyField import __init__ [as 别名]
def __init__(self, to, chained_field=None, chained_model_field=None,
auto_choose=False, **kwargs):
"""
examples:
class Publication(models.Model):
name = models.CharField(max_length=255)
class Writer(models.Model):
name = models.CharField(max_length=255)
publications = models.ManyToManyField('Publication', blank=True, null=True)
class Book(models.Model):
publication = models.ForeignKey(Publication)
writer = ChainedManyToManyField(
Writer,
chained_field="publication",
chained_model_field="publications",
)
name = models.CharField(max_length=255)
``chained_field`` is the name of the ForeignKey field referenced by ChainedManyToManyField of the same Model.
in the examples, chained_field is the name of field publication in Model Book.
``chained_model_field`` is the name of the ManyToMany field referenced in the 'to' Model.
in the examples, chained_model_field is the name of field publications in Model Writer.
``auto_choose`` controls whether auto select the choice when there is only one available choice.
"""
try:
isbasestring = isinstance(to, basestring)
except NameError:
isbasestring = isinstance(to, str)
if isbasestring:
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.chain_field = chained_field
self.chained_model_field = chained_model_field
self.auto_choose = auto_choose
ManyToManyField.__init__(self, to, **kwargs)
示例4: __init__
# 需要导入模块: from django.db.models.fields.related import ManyToManyField [as 别名]
# 或者: from django.db.models.fields.related.ManyToManyField import __init__ [as 别名]
def __init__(self, translated_field, language, to, *args, **kwargs):
self._related_pre_init(translated_field, language, *args, **kwargs)
ManyToManyField.__init__(self, to, **kwargs)
self._related_post_init()