Skip to content
Advertisement

django custom function for filter query

I’ve a field in my model called, test_data = models.TextField(...), and the model is called MyOrm

and this test_data contains data which is actually string, some holds JSON data, and some reference to blob-url.

Now I’m trying to streamline my data. So I want to filter all the MyOrm object whose test_data ain’t JSON.

I’m just storing/trying to store some meta-data along with url, then I will convert them.

Can anyone suggest me a way to do so??

pseudocode:

JavaScript

Advertisement

Answer

There is no database function for this that I’m aware of. You can define your own, but then this is more database programming.

I think you have no other option than to enumerate over the MyOrm model objects, and check if you can JSON decode these, with:

JavaScript

or if memory might be a problem, you can work with .iterator(…) [Django-doc]:

JavaScript
Advertisement