1

I want top perform django orm that selects first 3 word of letter as diustinct selection

I have model as below:

class Phone(models.Model):
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    name = models.CharField(max_length=2050,null=True,blank=True)
    slug = models.SlugField(max_length=2050,null=True,blank=True)

** sample values of name are **


Xiomi redmi note red ...., Xiomi redmi note blue ...., samsung galaxy s10 red ..., samsung galaxy s10 blue ...,

i want to extract the distinct queryset that has first three word as common

For example: Xiomi redmi note, samsung galaxy s10 as a resilt query set

José Ricardo Pla
  • 1,043
  • 10
  • 16
  • Which backend? You'll need to create a database-specific [Func](https://docs.djangoproject.com/en/2.2/ref/models/expressions/#func-expressions) expression, annotate on that and then filter on the annotation. – Endre Both Apr 17 '19 at 11:40
  • i am using Postgres as my backend. Database function includes the only character based operations such as LEFT , Substr ,strIndex, there is no function to split words – Aravindhan Mathiyazhagan Apr 17 '19 at 12:33
  • You can experiment with `split_part`, `position` and `substring(dbcolumn from regexpattern)`. – Endre Both Apr 17 '19 at 12:41

0 Answers0