Using Django RelatedField for user connection requests?

I am curious if a related interface can be used to create user connection requests. I would like to apply this in django-parler , a multilingual application for Django.

For example, when "slug" is a translated field, I would like to have:

MyModel.objects.filter(slug="foo") 

for work like:

  MyModel.objects.fiter(translations__slug="foo") 

under the hood. Is this possible with the relatedField class API, for example?

I noticed that there are several API hooks in the RelatedField class, such as m2m_reverse_field_name() , m2m_target_field_name() , m2m_column_name() , extra_filters() etc. which are used in GenericRelation and django-taggit TaggableManager , but I have no idea , how it works.

NB Field access to instances is covered in django-parler , and I would like to extend it to ORM requests.

+4
source share
1 answer

The docs say you can do this to filter by a specific translated field:

 MyObject.objects.filter( translations__language_code__in=get_active_language_choices(), translations__slug='omelette' ) 

This should satisfy your need for a request for the translated value of the slug field in a specific language.

+1
source

All Articles