How to get the app a Django model is from? -
i have model generic relation:
trackeditem --- genericrelation ---> model
i able generically get, initial model, tracked item.
i should able on model without modifying it.
to need content type , object id. getting object id easy since have model instance, getting content type not: contenttype.object.filter requires model (which content_object.__class__.__name__
) , app_label.
i have no idea of how in reliable way app in model is.
for app = content_object.__module__.split(".")[0]
, doesn't work django contrib apps.
you don't need app or model contenttype - there's handy method that:
contenttype.objects.get_for_model(myobject)
despite name, works both model classes , instances.
Comments
Post a Comment