我正在尝试使用 django-graphene 返回过滤结果,但它给出了关于 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
最佳答案
在 filter_fields
中指定 PatientType.Meta
属性为
class PatientType(DjangoObjectType):
class Meta:
model = Patients
exclude = ('active',)
interfaces = (relay.Node,)
filter_fields = ["field_1", "field_2"]
或者,您可以在 filter_fields=[]
部分中设置 filterset_class
或 Meta
属性更多示例可以在文档中找到,
GraphenePython- Filtering
关于django - Graphite 烯-django : 'Meta.model' without either 'Meta.fields' or 'Meta.exclude' has been deprecated since 0. 15.0 现在被禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64119033/