def contribute_to_class(self, cls, name):
super(Reference, self).contribute_to_class(cls, name)
# Create ReverseReference in the opposite direction unless related_name ends with '+'
if not self.related_name or not self.related_name.endswith('+'):
related_name = self.related_name or '%s_set' % cls.__name__.lower()
reverse_reference = ReverseReference(cls, field_name=self.field_name, one_to_one=self.one_to_one)
setattr_lazy(lambda objref=self._objref: lookup_by_objref(objref),
related_name, reverse_reference)
# Allow direct access to the reference without fetching the instance from the server first
getter = property(curry(self.foo_id_getter, field=self))
setter = getter.setter(curry(self.foo_id_setter, field=self))
setattr(cls, '%s_id' % self.field_name, setter)
评论列表
文章目录