Hi, I have a model with a recursive relation:
class Category(models.Model): name = models.CharField(max_length=100, blank=False, db_index=True) parent_category = models.ForeignKey('self', related_name='child_categories', blank=True, null=True) And I want it's members to be ordered with respect to the parent category, like so: Pets Pets -> Dogs Pets -> Cats Vehicles Vehicles -> cars etc. So that when a product is added, the category selection displays in a logical order. So I added to my model definintion the following: class Meta: order_with_respect_to = 'parent_category' All seems well, but when I run: python manage.py syncdb I get an error: [...] File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 178, in _prepare setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls)) AttributeError: 'str' object has no attribute 'get_categoty_order' This 'str' the error refers to is the 'self' in the foreign key relation in the model. This happens whenever you try to order_with_respect_to a model that has not yet been defined and you refer to it as a string. Which can be solved in most cases by moving that definition up in the models.py file and removing the quotes. But in this case the relation is recursive and the only way to accomplish it is to pass the string argument 'self' to my ForeignKey. Has anyone stumbled upon this matter before? I googled and found people complaining about this but no solutions... I hope someone can shed some light on the matter... Thanks, NicoEchaniz PS: the documentation[1] doesn't explain if there's a way to make to ordering work for recursive relations. http://docs.djangoproject.com/en/dev/ref/models/options/#order-with-respect-to --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---