Note that there are some explanatory texts on larger screens.

plurals
  1. POtastypie api not showing ForeignKey in json result
    primarykey
    data
    text
    <p>I recently started using tastypie to open up my api for a potential smartphone app.</p> <p><strong>I'm using python-2.7 and Django-1.1.2</strong></p> <p>Two things are confusing me</p> <p>1: in the <code>EntryResource</code> class when calling the <code>ForeignKey</code>, they just call the resource along with the resource_name, when I do it in such a way I get the following traceback.</p> <pre><code>691. assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT) Exception Type: AssertionError at /api/v1/activity-stream-item-subject/ Exception Value: ForeignKey(&lt;class 'api.resources.UserResource'&gt;) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self' </code></pre> <p>2: if I change <code>EntryResource</code> to <code>user = fields.ForeignKey(UserResource, 'user')</code>, then it runs fine without a traceback, however I cannot see the related information in the JSON response.</p> <p>api/resources.py</p> <pre><code>class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name = 'user' excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser'] filtering = { 'username': ALL, } class EntryResource(ModelResource): user = fields.ForeignKey(UserResource, 'user') class Meta: queryset = Entry.objects.all() resource_name = 'entry' authorization = Authorization() filtering = { 'user': ALL_WITH_RELATIONS, 'pub_date': ['exact', 'lt', 'lte', 'gte', 'gt'], } </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload