fields.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:django-composite-foreignkey 作者: onysos 项目源码 文件源码
def __init__(self, to, **kwargs):
        """
        create the ForeignObject, but use the to_fields as a dict which will later used as form_fields and to_fields
        """
        to_fields = kwargs["to_fields"]
        self.null_if_equal = kwargs.pop("null_if_equal", [])
        nullable_fields = kwargs.pop("nullable_fields", {})
        if not isinstance(nullable_fields, dict):
            nullable_fields = {v: None for v in nullable_fields}
        self.nullable_fields = nullable_fields

        # a list of tuple : (fieldnaem, value) . if fielname = value, then the field react as if fieldnaem_id = None
        self._raw_fields = self.compute_to_fields(to_fields)
        # hiro nakamura should have said «very bad guy. you are vilain»
        if "on_delete" in kwargs:
            kwargs["on_delete"] = self.override_on_delete(kwargs["on_delete"])

        kwargs["to_fields"], kwargs["from_fields"] = zip(*(
            (k, v.value)
            for k, v in self._raw_fields.items()
            if v.is_local_field
        ))
        super(CompositeForeignKey, self).__init__(to, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号