I have been trying to resolve this issue for the past 2 days, but I have not found a solution yet. I have scoured the internet, and ChatGPT, and attempted over 50 methods, but nothing seems to work.
Our Model:
class Order(models.Model):
Payment_Refrence = models.CharField(max_length=300, unique=True)
Order_ID = models.CharField(max_length=300, unique=True, default=unique_order_id)
OrderData = models.JSONField(max_length=100000, null=True, blank=True)
Order Data Creation
OrderDataCreate = {
'product_title': Product.title,
'product_description': Product.description,
'product_plans': ProductPlans,
'package': Package_name,
}
Dump Data:
CreateOrder = Order.objects.create(
OrderData=json.dumps(OrderDataCreate),
)
After Dump Data in Database ~ code from Database
"{\"product_title\": \"Redis API Implementition\", \"product_description\": \"Description Here\",}"
I have implemented this to search:
OrderData = Order.objects.all().order_by('-created_at')
if SearchQuery:
SearchQuery = inpvalidator.anyname_validation(SearchQuery)
search_filters = Q(OrderData__contains={'product_title': SearchQuery})
OrderData = OrderData.filter(search_filters)
print(f'Search Filtered=======>{OrderData.count()}')
I even tried this:
OrderData = OrderData.filter(OrderData__product_title__icontains=SearchQuery)