I'm using python2.7, django1.6, and apache2. I have enabled crossdomain access. I have tried with and without a crsf token. I have no idea what I'm doing wrong.
visiting: url/to/site/contacts/api/v1/adresponses/1 works properly so tastypie is set up. I can see ad responses.
Someone please help. I have been stuck trying to get tastypie to work for days now.
Here is my api.py
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
fields=['username', 'id']
allowed_methods = ['get']
authorization = Authorization()
authentication = Authentication()
class AdResponsesResource(ModelResource):
users = fields.ManyToManyField('contacts.api.UserResource', 'users',
related_name='adresponse')
class Meta:
queryset = AdResponses.objects.all()
resource_name = 'adresponses'
authorization = Authorization()
authentication = Authentication()
This is my ajax call
$(function (){
$.ajax({
url: 'url/to/site/contacts/api/v1/adresponses/1',
type: 'GET',
accepts: 'application/json',
dataType: 'json'
});
So I'm not entirely sure why my original posted js doesn't work but I saw this example http://django-tastypie.readthedocs.org/en/latest/cookbook.html and it works as expect. Maybe its because I didn't have a success function?
$.ajax({
url: '../../api/v1/user/',
contentType: 'application/json',
type: 'GET',
success: function(data, textStatus, jqXHR) {
// Your processing of the data here.
console.log(data);
}
});