Unsupported "istartwith" lookup for CharField or attachment not allowed

I have created several models using Django ORM.

class feed(models.Model):
    location = models.OneToOneField('feedlocation')

class feedlocation(models.Model):
    areaHash = models.CharField(max_length=100,default='')

      

Then I used the following code to find out the 'feed' on the same Hash area.

Feed.objects.filter(location__areaHash__istartwith='*****')

      

I got this error:

FieldError: Unsupported lookup 'istartwith' for CharField or join on the field not permitted.

      

What should I do to achieve this request?

+3


source to share


2 answers


This code is incorrect:

Feed.objects.filter(location__areaHash__istartwith='*****')

      



Try:

Feed.objects.filter(location__areaHash__startswith='*****')

      

+12


source


Another workaround could be using icontains (keeping case insensitive as @shacker pointed out):



Feed.objects.filter(location__areaHash__icontains='*****')

      

0


source







All Articles