Hi,

I have created two models as this:

|
classCampaign(models.Model):
    name =models.CharField(max_length=255)

classCampaignExt(Campaign):
    status =models.IntegerField()

|

In my APIView I do this:

|
defget(self,request,campaign_id,response_format=None):
        campaigns =CampaignExt.objects.raw("""\
          SELECT
            c.id,
            c.name,
            c.status
          FROM campaign c
          WHERE c.id = %(id)s
        """%{"id":campaign_id });
|

The traceback looks like this:
|
Traceback:
File".../env/lib/python3.4/site-packages/django/core/handlers/base.py"inget_response
111.response =wrapped_callback(request,*callback_args,**callback_kwargs)
File".../env/lib/python3.4/site-packages/django/views/decorators/csrf.py"inwrapped_view
57.returnview_func(*args,**kwargs)
File".../env/lib/python3.4/site-packages/django/views/generic/base.py"inview
69.returnself.dispatch(request,*args,**kwargs)
File".../env/lib/python3.4/site-packages/rest_framework/views.py"indispatch
403.            response =self.handle_exception(exc)
File".../env/lib/python3.4/site-packages/rest_framework/views.py"indispatch
400.            response =handler(request,*args,**kwargs)
File".../campaigns/views.py"inget
35.returnResponse({'result':serializer.data[0]})
File".../env/lib/python3.4/site-packages/rest_framework/serializers.py"indata
570.self._data =[self.to_native(item)foritem inobj]
File".../env/lib/python3.4/site-packages/rest_framework/serializers.py"in<listcomp>
570.self._data =[self.to_native(item)foritem inobj]
File".../env/lib/python3.4/site-packages/django/db/models/query.py"in__iter__
1553.raiseInvalidQuery('Raw query must include the primary key')

ExceptionType:InvalidQueryat /campaigns/4858
ExceptionValue:Rawquery must include the primary key
|

As I have the primary key in the query I reckon that this should work. But it seems that the CampaignExt model does not know about the primary key as if it has not inherited this from the Campaign model.

When I just create two models with a separated list of fields like this:

|
|classCampaign(models.Model):
    name =models.CharField(max_length=255)

classCampaignExt(||||models.Model||):
||||name =models.CharField(max_length=255)
||    status =models.IntegerField()
|
|

It works as expected. Can you help me what I am missing? Here is my environment:

Django 1.7.1
Python 3.4.2
Rest_Framework 2.4.3

Thanks,
   Tobias.
--
Gruß/Regards,
Tobias Wolff

/Senior Architect Workflow Solutions/
*IPONWEB GmbH*

Conrad-Niemann-Straße 28
33442 Herzebrock-Clarholz

Mobil: +49 172 1940702
eMail: two...@iponweb.net

Geschäftsführer: Thomas Servatius
Amtsgericht: Düsseldorf, HRB 72195

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5450EA6E.4010000%40iponweb.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to