python - Django - Filter queryset by CharField value length -


Given that I have a code with CharField or CharField Heritage model is based model field such as:

  class MyModel (models.Model): name = models.CharField (max_length = 1024, ...) ...  

I need to create a migration because it has the maximum max_length 255. Firstly I am writing datamigration , which is any value with more than 255 characters To make the upcoming schemamigration set the maximum length of the column Customize for, which I'll do right after this work.

The issue is that I have a large data set and I do not know that in all the rows <00> MyModel has more than 255 characters. Name < / Code> and I would like to consider my migration, which only do.

Is there any way to filter the only object that meets this condition, the DEGENGO ORM? Something like this:

  MyModel.objects.filter (name__len__gte = 255)  

It would be great, but I believe this is not possible, Or at least it

thanks!

itemprop = "text">

In the 'latest' Django versions django.db.functions .length is created in lookup / conversion, so that you can do this:

  Old Answer:     

< / P>

.objects.extra (where = ["CHAR_LENGTH (text)> 254"])

or humiliating the reggae lookup, I'm assuming it will slow down:

  MyModel.objects.filter (text__regex = r '^. {254}. * ')  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -