When i try to filter the object with the name that i got from the json data the queryset is empty but when i try to filter it with hardcoded value the queryset exists. The name is exactly same in the json data and in the object but it returns empty. name = w.get('name') its type is str. The value is new_template_duke_1 Can you please help why the queryset is empty in this line templates = templates.filter(template_name=name)
waba = res.get('waba_templates') templates = MerchantWhatsappTemplate.objects.filter( merchant=merchant, approved=False, rejected=True ) qs = templates.filter(template_name="new_template_duke_1") print(qs) <<<<<<<< Not empty if not templates.exists(): return for w in waba: category = w.get('category') name = w.get('name') <<<<<< "new_template_duke_1" status = w.get('status').upper() rejected_reason = w.get('rejected_reason') templates = templates.filter( template_name=name ) print(templates) <<<<<<< Empty queryset "waba_templates": [{ "category": "AUTO_REPLY", "components": [ { "text": "body with emoji 😀 and variable 1", "type": "BODY" }, { "format": "TEXT", "text": "New header with variable 1", "type": "HEADER" }, { "text": "footer available", "type": "FOOTER" ], "language": "en", "name": "new_template_duke_1", "rejected_reason": "INVALID_FORMAT", "status": "rejected" }, https://stackoverflow.com/questions/67238395/filtering-objects-with-json-data-django April 24, 2021 at 08:53AM
没有评论:
发表评论