Searching or filtering on translated relationships with Django-hvad

485 views Asked by At

I've got a model which supports translated fields which is included as a filter field on a related model's admin definition;

class Event(TranslatableModel):
    """ The Event model. """
    translations = TranslatedFields(
        title = models.CharField(
            verbose_name=_("Title"),
            max_length=255,
            db_index=True
        )
    )

@admin.register(Participant)
class ParticipantAdmin(admin.ModelAdmin):
    list_filter = (
        'notified',
        'completed',
        'enabled',
        'user__client',
        'events__title',
    )

@admin.register(Event)
class EventAdmin(TranslatableAdmin):
    list_display = (
        'title_', 'date', 'enabled'
    )

This causes the WrongManager error from HVAD;

hvad.exceptions.WrongManager: To access translated fields like 'title' from an untranslated model, you must use a translation aware manager. For non-translatable models, you can get one using hvad.utils.get_translation_aware_manager. For translatable models, use the language() method.

I've found some discussion on the django-hvad github issues which suggests the need to override get_search_results() to handle custom functionality. Is this the best way to go about search/filtering? I've got a language attribute on the User so using that with the override may be a solution.

0

There are 0 answers