tastypie

heroku, postgreSQL, django, comments, tastypie: No operator matches the given name and argument type(s). You might need to add explicit type casts

核能气质少年 提交于 2019-11-27 03:09:10
问题 I have a simple query on django's built in comments model and getting the error below with heroku's postgreSQL database: DatabaseError: operator does not exist: integer = text LINE 1: ... INNER JOIN "django_comments" ON ("pi ns_pin"."id" = "django_... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. After googling around it seems this error has been addressed many times before in django, but I'm still getting it (all related issues

How to create or register User using django-tastypie API programmatically?

孤街醉人 提交于 2019-11-27 00:30:45
问题 My code below kinda works, it creates the User object and saves but it doesn't save the password: class CreateUserResource(ModelResource): class Meta: allowed_methods = ['post'] object_class = User authentication = Authentication() authorization = Authorization() include_resource_uri = False fields = ['username'] def obj_create(self, bundle, request=None, **kwargs): try: bundle = super(CreateUserResource, self).obj_create(bundle, request, **kwargs) except IntegrityError: raise BadRequest(

Django Tastypie: How to Authenticate with API Key

妖精的绣舞 提交于 2019-11-26 18:16:37
问题 I'm making an internal API with TastyPie. I have from tastypie.authentication import ApiKeyAuthentication class MyResource(ModelResource): Meta: authentication = ApiKeyAuthentication() With Auth rules disabled, my API works great. With it on, I get a 401 (UNAUTHORIZED) response no matter what I try. I'm sure this is one of those things that's really obvious once you've see it in action, but in the meantime, please advise how to to make the request (a GET). 回答1: Add the username and api_key

How can I login to django using tastypie

吃可爱长大的小学妹 提交于 2019-11-26 18:14:59
I'm trying to override is_authenticated in my custom authentication. I have something simple (to start with) like this: class MyAuthentication(BasicAuthentication): def __init__(self, *args, **kwargs): super(MyAuthentication, self).__init__(*args, **kwargs) def is_authenticated(self, request, **kwargs): return True then in my ModelResource I have class LoginUserResource(ModelResource): class Meta: resource_name = 'login' queryset = User.objects.all() excludes = ['id', 'email', 'password', 'is_staff', 'is_superuser'] list_allowed_methods = ['post'] authentication = MyAuthentication()

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

流过昼夜 提交于 2019-11-26 15:53:33
问题 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) | Q(email__icontains=query) ) results = Business.objects.filter(qset).distinct() I have tried the following using

Django-tastypie: Any example on file upload in POST?

*爱你&永不变心* 提交于 2019-11-26 11:06:52
问题 Could anyone give a complete example on using the tastypie FileField, both server-side and client-side please? Here\'s what I have tried: #models.py class Foo(models.Model): img = models.ImageField(upload_to=\"images\", null=True, blank=True) body = models.CharField() #api.py class FooResource(ModelResource): img = fields.FileField(attribute=\"image\", null=True, blank=True) class Meta: queryset = Foo.objects.all() If I try to create a foo object using curl, e.g., >>> curl -F \"body=test\" -F

How can I login to django using tastypie

强颜欢笑 提交于 2019-11-26 06:15:53
问题 I\'m trying to override is_authenticated in my custom authentication. I have something simple (to start with) like this: class MyAuthentication(BasicAuthentication): def __init__(self, *args, **kwargs): super(MyAuthentication, self).__init__(*args, **kwargs) def is_authenticated(self, request, **kwargs): return True then in my ModelResource I have class LoginUserResource(ModelResource): class Meta: resource_name = \'login\' queryset = User.objects.all() excludes = [\'id\', \'email\', \