मैं अपने एपीआई को टस्टपी के साथ रिवर्स रिलेशनशिप डेटा देने की कोशिश कर रहा हूं।टेस्टपी रिवर्स रिलेशन
DocumentContainer कई DocumentEvents
यहाँ है मेरे कोड है:
मैं दो मॉडल, DocumentContainer के रूप में है, और DocumentEvent, वे संबंधित हैं
class DocumentContainerResource(ModelResource):
pod_events = fields.ToManyField('portal.api.resources.DocumentEventResource', 'pod_events')
class Meta:
queryset = DocumentContainer.objects.all()
resource_name = 'pod'
authorization = Authorization()
allowed_methods = ['get']
def dehydrate_doc(self, bundle):
return bundle.data['doc'] or ''
class DocumentEventResource(ModelResource):
pod = fields.ForeignKey(DocumentContainerResource, 'pod')
class Meta:
queryset = DocumentEvent.objects.all()
resource_name = 'pod_event'
allowed_methods = ['get']
जब मैं अपने API URL मारा, मैं निम्न त्रुटि प्राप्त करें:
DocumentContainer' object has no attribute 'pod_events
क्या कोई मदद कर सकता है?
धन्यवाद।
हम्म, परिवर्तन के बाद भी, यह मेरे लिए काम नहीं करता था। अब यह कहता है कि "DocumentContainer 'ऑब्जेक्ट में कोई विशेषता नहीं है' pod_event_set '" – rookieRailer
@rookieRailer क्या आप अपने models.py से संबंधित स्निपेट पोस्ट करना चाहते हैं? –
विदेशीकी ToOneField के लिए एक उपनाम है। –