Coder Social home page Coder Social logo

tastypie-generic's People

Contributors

achur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tastypie-generic's Issues

handling Lazy import

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 :)

Seem to doesn't work on Django 1.4

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']

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.