achur / tastypie-generic Goto Github PK
View Code? Open in Web Editor NEWGeneric Foreign Keys and other tools for Django-Tastypie
Generic Foreign Keys and other tools for Django-Tastypie
Hi,
Is there a particular reason that explains why the lazy import are not handled in the GenericForeignKey?
What would be great is if it was possible to do something like this:
content_object = GenericForeignKeyField({
'module.User': 'module.UserResource',
'module.Event': 'module.EventResource',
}, 'content_object')
In that case, the objects, passed as string, would be imported at runtime only. That would avoid circular inclusion conflicts in some case...
Thanks for your work on this repo :)
I try to use tastypie-generic on Django 1.4 (Python 2.6.6 -> Debian 6.0.5) with the last version of tastypie (easy_install django tastypie tastypie-generic). But I always got an error :
'str' object has no attribute 'creation_counter'
<response>
<error_message>'str' object has no attribute 'creation_counter'</error_message>
<traceback>
Traceback (most recent call last): File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/django_tastypie-0.9.11-py2.6.egg/tastypie/resources.py", line 192, in wrapper response = callback(request, *args, **kwargs) File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/django_tastypie-0.9.11-py2.6.egg/tastypie/resources.py", line 397, in dispatch_list return self.dispatch('list', request, **kwargs) File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/django_tastypie-0.9.11-py2.6.egg/tastypie/resources.py", line 427, in dispatch response = method(request, **kwargs) File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/django_tastypie-0.9.11-py2.6.egg/tastypie/resources.py", line 1037, in get_list to_be_serialized['objects'] = [self.full_dehydrate(bundle) for bundle in bundles] File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/django_tastypie-0.9.11-py2.6.egg/tastypie/resources.py", line 654, in full_dehydrate bundle.data[field_name] = field_object.dehydrate(bundle) File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/django_tastypie-0.9.11-py2.6.egg/tastypie/fields.py", line 621, in dehydrate foreign_obj = getattr(bundle.obj, self.attribute) File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/contrib/contenttypes/generic.py", line 121, in __get__ f = self.model._meta.get_field(self.ct_field) File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/db/models/options.py", line 291, in get_field if f.name == name: File "/home/developer/.virtualenvs/mysoft_core/lib/python2.6/site-packages/Django-1.4-py2.6.egg/django/db/models/fields/__init__.py", line 128, in __cmp__ return cmp(self.creation_counter, other.creation_counter) AttributeError: 'str' object has no attribute 'creation_counter'
</traceback>
</response>
here my model:
class MetaData(models.Model):
key = models.CharField(max_length = 100)
_value = models.TextField(db_column='value', blank=True)
def set_value(self, value):
self._value = base64.encodestring(value)
def get_value(self):
return base64.decodestring(self._value)
value = property(get_value, set_value)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey(content_type, object_id)
class Meta:
app_label = "core"
permissions = (
('can_view_metadata','Can view meta data'),
)
and here my Resource:
class MetaDataResource(ModelResource):
content_object = GenericForeignKeyField({
Article : ArticleResource,
}, 'content_object')
class Meta:
queryset = MetaData.objects.all()
resource_name = 'metadata'
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
excludes = ['object_id']
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.