muh*_*san 6 django django-filter graphql
我正在尝试使用 django-graphene 返回过滤结果,但它给出了有关错误消息的错误
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
Run Code Online (Sandbox Code Playgroud)
filter_fields在PatientType.Metaas中指定属性
class PatientType(DjangoObjectType):
class Meta:
model = Patients
exclude = ('active',)
interfaces = (relay.Node,)
filter_fields = ["field_1", "field_2"]Run Code Online (Sandbox Code Playgroud)
或者,您可以在部分中设置filter_fields=[]或filterset_class属性Meta
更多示例可以在文档中找到,GraphenePython- Filtering
| 归档时间: |
|
| 查看次数: |
2998 次 |
| 最近记录: |