tastypie

Django (JSONField) and tastypie

半世苍凉 提交于 2019-12-01 16:41:13
I have a table into mysql that is the type TextField (django) by using the JSONField. This is how my model looks from django.db import models from json_field import JSONField class Model(models.Model): obj = JSONField() The value I send via tastypie is json_string = '{"data":"value"}' Into the database I can see {"data":"value"} But when retrive the data with curl I get something like this "{u'data': u'value'}" What I can do to not have the python u'field' representation into the tastypie's output ? thanks! I fixed this issue like so: def dehydrate_user_inputs(self, bundle): requirement =

Django (JSONField) and tastypie

梦想与她 提交于 2019-12-01 16:04:24
问题 I have a table into mysql that is the type TextField (django) by using the JSONField. This is how my model looks from django.db import models from json_field import JSONField class Model(models.Model): obj = JSONField() The value I send via tastypie is json_string = '{"data":"value"}' Into the database I can see {"data":"value"} But when retrive the data with curl I get something like this "{u'data': u'value'}" What I can do to not have the python u'field' representation into the tastypie's

AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

佐手、 提交于 2019-12-01 15:36:45
I keep getting the below errors in my sentry exceptions AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module' And the trace only points to code withing the django code base without pointing to any place in my application. My logs are clean too. What could be a possible reason for this? raise Resolver404({'path' : path}) @property def urlconf_module(self): try: return self._urlconf_module except AttributeError: self._urlconf_module = import_module(self.urlconf_name) return self._urlconf_module @property 'self' <RegexURLResolver urls (None:None) ^/> Otherwise on the

AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'

北慕城南 提交于 2019-12-01 14:29:08
问题 I keep getting the below errors in my sentry exceptions AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module' And the trace only points to code withing the django code base without pointing to any place in my application. My logs are clean too. What could be a possible reason for this? raise Resolver404({'path' : path}) @property def urlconf_module(self): try: return self._urlconf_module except AttributeError: self._urlconf_module = import_module(self.urlconf_name)

How to put Product to Cart via tasytpie API?

雨燕双飞 提交于 2019-12-01 10:26:11
Let's assume we have these models, original project differs but this would be the common task: class Cart(models.Model): owner = models.ForeignKey(User) products = models.ManyToManyField(Product, symmetrical=False) class Product(models.Model): title = models.CharField(max_length="255") description = models.TextField() Now I want to put a Product into the Cart via the api. I started like this: class CartResource(ModelResource): products = fields.ManyToManyField(ProductResource, 'products', full=True) def override_urls(self): return [ url(r"^(?P<resource_name>%s)/product/(?P<prodcut_id>\w[\w/-]*

Django Tastypie, ManyToMany Saving Error

大憨熊 提交于 2019-12-01 10:15:51
问题 i got a problem when i'm saving an item, via tastypie api. (POST method) Here is my api.py code. from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS from tastypie.authorization import DjangoAuthorization from tastypie.authentication import BasicAuthentication from tastypie import fields from apps.clients.models import Client from django.contrib.auth.models import User class ClientAPI(ModelResource): users = fields.ToManyField('apps.clients.api.ClientUserAPI', 'users',related

Deleting objects in django tastypie

我与影子孤独终老i 提交于 2019-12-01 09:22:56
I have the following models: class Poster(models.Model) user = models.OneToOneField(User, primary=True) userpicture = models.CharField(max_length = 128 =True) class Posts(models.Model) poster = models.ForeignKey(Poster, related_name = 'post_owner') url = models.CharField(max_length = 128) time = models.DateTimeField(auto_now_add=True) class Comment(models.Model): user = models.ForeignKey(Poster) post = models.ForeignKey(Posts) time = models.DateTimeField(auto_now_add=True) comment = models.CharField(max_length=140) A poster can make a post and other posters can comment on that post. Kind of

Tastypie: JSON header to use UTF-8

老子叫甜甜 提交于 2019-12-01 06:55:03
问题 I'm using tastypie to return a Resource and one of its fields is in Arabic hence need to be in UTF-8 vs Unicode, which is what I'm assuming is the case in running its schema: "word": {..., "help_text": "Unicode string data. Ex: \"Hello World\"", ...} Here's sample json returned, note the garbled field of word: {"approved": false, "id": 12, "resource_uri": "/api/v1/resource/12/", "word": "اه"} 回答1: This is because they patched Tastypie to no longer send charset=utf-8 when content-type is

How to put Product to Cart via tasytpie API?

半城伤御伤魂 提交于 2019-12-01 05:41:53
问题 Let's assume we have these models, original project differs but this would be the common task: class Cart(models.Model): owner = models.ForeignKey(User) products = models.ManyToManyField(Product, symmetrical=False) class Product(models.Model): title = models.CharField(max_length="255") description = models.TextField() Now I want to put a Product into the Cart via the api. I started like this: class CartResource(ModelResource): products = fields.ManyToManyField(ProductResource, 'products',

get request parameters in Tastypie

孤街浪徒 提交于 2019-11-30 23:37:31
I am building a REST API for my application that uses a NoSQL db (Neo4j) using Tastypie. So I overrode some main methods of the class tastypie.resources.Resource to do so, and currently struggling to implement def obj_get_list(self, request=None, **kwargs): which is supposed to return a list of objects. Actually, I want to pass a parameter to this method through the url (something like http://127.0.0.1:8000/api/airport/?query='aQuery' ) and then perform a query based on this parameter. The problem is that the request is None so I can't get its parameter ! When printing the kwargs variable, I