Enable parent references to ModelField

#11 · closed · 0 comments

View on GitHub ↗

ericmoritz

I would like to allow a Model field to be able to access it's parent. For instance Something like the following: ``` class Person(Model): name = CharField() car = ModelField(Car, related_name="owner") class Car(Model): make = CharField() model = CharField() data = {"name": "Eric Moritz", "car": {"make": "Chrysler", "model": "Sebring"}, } me = Person.from_dict(data) assert me.car.owner == me ``` I believe that we should only enable this behavior if someone provides a related_name argument to ModelField and ModelCollectionField. This will preserve backwards-compatibility.

Comments