2

I'm trying to use Django ORM where it queries an API rather than a database. I found the library Django Rest Models which does this in conjunction with the library dynamic-rest.

My model is called Client, and when I run:

Client.objects.filter(id=62)

I'm getting the following error:

ImproperlyConfigured: the response does not contains the result for client.  
maybe the resource name does not match the one on the api. please check if 
Client.APIMeta.resource_name_plural is ok had [u'last_name', u'first_name', 
u'agent',...] in result

Can anyone help me understand how to fix this error?

Additional Info

This is my model on the client

class Client(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    agent = models.ForeignKey(Agent, db_column='agent')
    .....


    class APIMeta:
        resource_path = 'clients'
        resource_name = 'client'
        resource_name_plural = 'clients'
        pass

This is my code on the API

class ClientSerializer(DynamicModelSerializer):
    agent = DynamicRelationField('AgentSerializer')
    class Meta:
        fields = '__all__'
        model = Client
        name = 'client'


class AgentSerializer(DynamicModelSerializer):

    client = DynamicRelationField('ClientSerializer', many=True)

    class Meta:
        fields = '__all__'
        model = Agent

Update

After debugging, I have found that the data is returning without the name of the model as a key. How do I return the data in the required format?

2 Answers2

1

django-rest-models is heavily dependent on dynamic-rest framework.
It's important to read the docs of dynamic-rest before attempting to use django-rest-models.

In this case the viewsets were inheriting from ModelViewSet when they should have been inheriting from DynamicModelViewSet.

Elisha
  • 4,811
  • 4
  • 30
  • 46
0

In your models.py, you have no traces of a field called 'id'. Though it automatically takes a field when storing your data in the database. It requires a separate field when you call it for data retrieval. Try to add 'id' field.

class Client(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    agent = models.ForeignKey(Agent, db_column='agent')
    .....


class APIMeta:
    resource_path = 'clients'
    resource_name = 'client'
    resource_name_plural = 'clients'
    pass
Maria Irudaya Regilan J
  • 1,426
  • 1
  • 11
  • 22