Thank you, Michael. Tried several combinations but it doesn't work
either.

1. First I tried to use Category.objects.all():
 c = Category.objects.all()
 serializers.serialize("json", c)

and got the same error.

2. Then tried to init some variable with s[:5] and the result didn't
change.

3. When I use some other model which doesn't refer to itself (is a non
recursive) it works fine even when using with lazy filter calls
similar to my first example.

Anthony

On Apr 1, 5:34 am, Michael <[EMAIL PROTECTED]> wrote:
> Your error is actually coming from the fact that you are not getting
> any results from your filter query. The reason that the error is
> appearing on the second line of your script is because filter is a
> lazy call and isn't really made until you ask it to return objects in
> this bit: s[:5]. Change your filter or call Category.objects.all() it
> should work.
>
> Hope that helps,
> Michael
>
> On Mon, Mar 31, 2008 at 5:39 AM, Legioneer <[EMAIL PROTECTED]> wrote:
>
> >  Hi All,
>
> >  I'm trying to serialize recursive model (a category which refers to
> >  itself) and get a 'DoesNotExist: Category matching query does not
> >  exist', while other models work fine. Does anyone know a clue for
> >  this?
>
> >  I'm doing like this:
>
> >  from django.core import serializers;
> >  from newproject.models import Category
>
> >  s = Category.objects.filter(parent__exact='0')
> >  serializers.serialize("json", s[:5])
>
> >  and get:
> >  Traceback (most recent call last):
> >   File "<console>", line 1, in ?
> >   File "/usr/lib/python2.3/site-packages/django/core/serializers/
> >  __init__.py", line 72, in serialize
> >     s.serialize(queryset, **options)
> >   File "/usr/lib/python2.3/site-packages/django/core/serializers/
> >  base.py", line 48, in serialize
> >     self.handle_fk_field(obj, field)
> >   File "/usr/lib/python2.3/site-packages/django/core/serializers/
> >  python.py", line 41, in handle_fk_field
> >     related = getattr(obj, field.name)
> >   File "/usr/lib/python2.3/site-packages/django/db/models/fields/
> >  related.py", line 209, in __get__
> >     rel_obj = self.field.rel.to._default_manager.get(**params)
> >   File "/usr/lib/python2.3/site-packages/django/db/models/manager.py",
> >  line 69, in get
> >     return self.get_query_set().get(*args, **kwargs)
> >   File "/usr/lib/python2.3/site-packages/django/db/models/query.py",
> >  line 263, in get
> >     raise self.model.DoesNotExist, "%s matching query does not exist."
> >  % self.model._meta.object_name
> >  DoesNotExist: Category matching query does not exist.
>
> >  Anthony
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to