So versuche ich meine Lage Filter URL zu haben als api/v1/labels/?brand_location=Australia
Marken zu filtern mit nur Australien Marken die Fehlermeldung zurück, sondern halten Empfang:Ungültige Ressourcensuche Daten zur Verfügung gestellt (nicht übereinstimmen Typ)
{"error": "Invalid resource lookup data provided (mismatched type)."}
Aber wenn Gebrauch api/v1/labels/?brand_location/=Australia
funktioniert, aber doest Filter nur Australien Standorte, gibt es die vollständige Antwort nicht Standorte ausgeschlossen.
Also meine Fragen sind:
- Wie kann ich den Slash entfernen? Und lasst es nur Australien filtern
- Ist das der richtige Weg? Bei Verwendung von Fremdschlüsseln mit Django Tastypie?
Mein Code unten:
Models.py
class Brand(models.Model):
brand_location = models.ForeignKey('Location', null=True, blank=True, default="")
class Location(models.Model):
state_or_country = models.CharField(unique=True, max_length=200, blank=True, default="", verbose_name=_('Location'),
api.py
class LocationResource(ModelResource):
class Meta:
excludes = ['modified', 'id', 'created']
queryset = Location.objects.all()
resource_name = 'locations'
class LabelResource(ModelResource):
brand_location = fields.ForeignKey(LocationResource, 'brand_location', full=True)
class Meta:
filtering = {
"brand_location": ALL
}
queryset = Brand.objects.all()
resource_name = 'labels'
Snippet JSON Antwort
{
"labels": [
{
"brand_location": {
"state_or_country": "Australia"
}
}
],
"meta": {
"limit": 6,
"next": "/unlabel-network/unlabel-network-api/v1/labels/?limit=6&brand_location%2F=Australia&offset=6",
"offset": 0,
"previous": null,
"total_count": 128
}
}
Dies ist das neue Fehler, den ich erhalte, wenn ich die oben angegebene URL benutze: {"error": "Suchvorgänge sind nicht mehr als eine Ebene tief im Feld 'brand_location' erlaubt."} – Amechi