inspect - Django: find all OneToOneFields pointing to a Model -


I am writing a routine to inspect an example and to find all its relationships (for example example ._meta.get_all_related_objects () ), but I can not find a way to get to a one-to-field relationship.

For example, with these two models:

  class main. Model): ... class extension (models.Model): ... main = model. An internal field (main, primary_key = true)   

A 'main' example should be given that I should get one related to OneToOne Objects / Classes (clearly without crushing their names).

How can I do this?

model deaf by django.db import all_models_with_oto (the_model): model of "model" For model for model, model-list = returns [models] to all models. Field: ifinstance (area, models.OneToOneField): if field.rel.to == the_model: model_list.append (model) returns model_list

list indexed version (ironically slower, probably due to < Code> any and for nested lists):

  def all_models_with_oto (the_model): "" "Returns all models that have one-one- Models for the "model" model go back to the model .get_models () model if any (for model (model, model.oneToOneField) and field.rel.to == field_meta.fields_model))    

Comments