本文整理汇总了Python中django.db.models.fields.related.ForeignKey.contribute_to_class方法的典型用法代码示例。如果您正苦于以下问题:Python ForeignKey.contribute_to_class方法的具体用法?Python ForeignKey.contribute_to_class怎么用?Python ForeignKey.contribute_to_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.fields.related.ForeignKey
的用法示例。
在下文中一共展示了ForeignKey.contribute_to_class方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import contribute_to_class [as 别名]
def _register(model, field_name, related_name, model_registry, model_map):
""" Set up the foreign keys on the `Action` model """
if model in model_registry:
return
model_registry.append(model)
field = ForeignKey(model, related_name=related_name, blank=True, null=True,
db_index=True)
field.contribute_to_class(Action, field_name)
model_map[model] = [related_name, field_name]
示例2: register
# 需要导入模块: from django.db.models.fields.related import ForeignKey [as 别名]
# 或者: from django.db.models.fields.related.ForeignKey import contribute_to_class [as 别名]
def register(model, field_name=None, related_name=None, lookup_method_name='get_follows'):
"""
This registers any model class to be follow-able.
"""
if model in registry:
return
registry.append(model)
if not field_name:
field_name = 'target_%s' % model._meta.module_name
if not related_name:
related_name = 'follow_%s' % model._meta.module_name
field = ForeignKey(model, related_name=related_name, null=True,
blank=True, db_index=True)
field.contribute_to_class(Follow, field_name)
setattr(model, lookup_method_name, get_followers_for_object)
model_map[model] = [related_name, field_name]