Pergunta

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 = ?
Foi útil?

Solução

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()

Outras dicas

Thanks gwaramadze! Here is a similar answer if you have an object:

object._meta.get_field(field_name).related_query_name()
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top