-1

I'm trying to fetch users list based on their language(from ArrayField). A single user can have multiple languages. When i passed single language{'Hindi'}, it fetches all the records except user with multiple languages, but if passed parameters {'Hindi','bangla','kannada'} then it gives me a specific record,how can i fetch the users list with hindi and other than hindi as well . I have tried with .all also but it didn't worked for me. Any help would be appreciated.

enter image description here

enter image description here models.py

# DESCRIPTION: This function gets the drivers list by lang.
    @classmethod
    def get_driver_by_lang(cls, driver_lang):
        try:
            driver_details = cls.objects.filter(language = driver_lang)
            data = serializers.serialize("json", driver_details)
            data = json.loads(data)
            return data
        except :
            return False
Prathamesh Doke
  • 797
  • 2
  • 16
  • 38
  • try the suggested answer and the comment. – xxbinxx Jul 22 '19 at 06:20
  • also you probably have the wrong database design. searching for specific array elements can be a sign of database misdesign. check this [answer](https://stackoverflow.com/a/36742834/3868653) – xxbinxx Jul 22 '19 at 06:20

1 Answers1

2

How about this:

driver_details = cls.objects.filter(language__contains = driver_lang)
mhd
  • 4,561
  • 10
  • 37
  • 53