2010/5/17 Alper Çuğun <al...@aardverschuiving.com>: > Hello, > > A quick Google search reveals a ton of confusion about: > Meta: order_with_respect_to > > I have an abbreviated Model: > > class NewsItem(models.Model): > # newsitems will be linked to blogs and projects > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey() > > > class Meta: > order_with_respect_to = 'content_object' > > And this fails to validate with the following error: > > django.db.models.fields.FieldDoesNotExist: NewsItem has no field named > 'content_object' > > > Clearly this is not true, so I think this is a bug, but more > importantly how can I make this work properly?
Well... it is true, of a fashion. content_object isn't a model field - it's a generic object, which isn't the same as a normal model field. In this case, what we have is a case where the implementation hasn't been fully developed for generic keys. If you're looking for a workaround, you'll essentially have to build a custom field with pre-save behavior that updates the value of the field based on the number of related objects that currently exists in the database. For the record, this is pretty much what order_with_respect_to does already, although implemented in a slightly different way. The real solution is to correct the implementation of order_with_respect_to so that it can handle generic keys - or better still, abstract the special case of generic keys so that any similar extension can be handled in the same way. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.