Reputation: 63
I'm trying to return filtered results using django-graphene but it gives an error about error-message
class PatientType(DjangoObjectType):
class Meta:
model = Patients
exclude = ('active',)
interfaces = (relay.Node,)
class PatientsQuery(ObjectType):
get_patient = graphene.Field(PatientType, id=graphene.Int())
all_patients = graphene.List(
PatientType, first=graphene.Int(), skip=graphene.Int(), phone_no=graphene.Int()
)
upcoming_appointments = DjangoFilterConnectionField(PatientType)
@permissions_checker([IsAuthenticated, CheckIsOrganizationActive])
def resolve_upcoming_appointments(self, info, **kwargs) -> List:
d = datetime.today() - timedelta(hours=1)
settings.TIME_ZONE # 'Asia/Karachi'
aware_datetime = make_aware(d)
res = Patients.objects.filter(appointments__booking_date__gte=aware_datetime,
appointments__booking_date__day=aware_datetime.day,
appointments__status=True)
if res:
return res
return []
class Query(
organization_schema.OrganizationQuery,
inventory_schema.MedicineQuery,
patient_schema.PatientsQuery,
graphene.ObjectType,
):
pass
Upvotes: 6
Views: 3273
Reputation: 88519
Specify the filter_fields
attribute in the PatientType.Meta
as
class PatientType(DjangoObjectType):
class Meta:
model = Patients
exclude = ('active',)
interfaces = (relay.Node,)
filter_fields = ["field_1", "field_2"]
Alternatively, you can either set the filter_fields=[]
or filterset_class
attribute in the Meta
section
More examples can be found in the doc, GraphenePython- Filtering
Upvotes: 9