tastypie

Testing Django throttling

Testing Django throttling Question: I’m throttling using TastyPie, but want to add a test to make sure it’s working properly. Is there an easy way to simulate 100 requests in a Django test (or hopefully some easier method) to test this? Asked By: Cisplatin || Source Answers: I’d recommend http://locust.io/, which is a great load …

Total answers: 1

How to change status of JsonResponse in Django

How to change status of JsonResponse in Django Question: My API is returning a JSON object on error but the status code is HTTP 200: response = JsonResponse({‘status’: ‘false’, ‘message’: message}) return response How can I change the response code to indicate an error? Asked By: Dhanushka Amarakoon || Source Answers: Return an actual status …

Total answers: 5

Django Tastypie Override URL with slug

Django Tastypie Override URL with slug Question: I have the following code: def override_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<slug>[wd_.-]+)/$" % self._meta.resource_name, self.wrap_view(‘dispatch_detail’), name="api_dispatch_detail"), ] Which produces an URL like: /api/v1/nodes/<slug>/ Everything is fine except that self.get_resource_uri(bundle) returns /api/v1/nodes/<id>/ and I cannot compare the current URL with the resource URI effectively. What am I doing wrong? Solution: working …

Total answers: 2

Django Tastypie Advanced Filtering: How to do complex lookups with Q objects

Django Tastypie Advanced Filtering: How to do complex lookups with Q objects Question: I have a basic Django model like: class Business(models.Model): name = models.CharField(max_length=200, unique=True) email = models.EmailField() phone = models.CharField(max_length=40, blank=True, null=True) description = models.TextField(max_length=500) I need to execute a complex query on the above model like: qset = ( Q(name__icontains=query) | Q(description__icontains=query) …

Total answers: 3

How to expose a property (virtual field) on a Django Model as a field in a TastyPie ModelResource

How to expose a property (virtual field) on a Django Model as a field in a TastyPie ModelResource Question: I have a property in a Django Model that I’d like to expose via a TastyPie ModelResource. My Model is class UserProfile(models.Model): _genderChoices = ((u”M”, u”Male”), (u”F”, u”Female”)) user = Models.OneToOneField(User, editable=False) gender = models.CharField(max_length=2, choices …

Total answers: 2

What Python framework for a REST/JSON web service with no front end?

What Python framework for a REST/JSON web service with no front end? Question: I need to create a Python REST/JSON web service for an iOS app to interact with. There will be no front end on the web. What will be the fastest, most lightweight framework to use for this? Learning curve to implement also …

Total answers: 6