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)
评论列表
文章目录