djangodjango-modelsdjango-contenttypes

Django. How to get related_name of a field from the contenttypes framework


How can I retrieve a related_name of a known field using content types framework?

I have reached as far as getting the actual field. But I have no idea how to lay hands on it's arguments.

field = content_type.model_class()._meta.get_field_by_name('field_name')
related_name = ?

Solution

  • OK, got it. As a reminder, field_name is what I know, it's hardcoded.

    related_name = content_type.model_class().field_name.field.related_query_name()