On 04/04/07, James Turnbull <[EMAIL PROTECTED]> wrote: > > I'm trying to group items in the Admin interface based on a foreign > key, and I'm hitting a few stumbling blocks. > > Simplified objects are... > > > class MenuItem(models.Model): > > name = models.CharField(maxlength=200) > > > > class Page(models.Model): > > name = models.CharField(maxlength=200) > > menu_item = models.ForeignKey('MenuItem', blank=True, null=True) > > > > class Meta: > > ordering = ('menu_item_id') > > What I want is on the "Page" admin screen to display the objects in > the order of their related MenuItems. > > I managed to get this to work, using the above argument of > 'menu_item_id', but manage.py gives the following error: > > > Error: Couldn't install apps, because there were errors in one or > > more models: > > pages.page: "ordering" refers to "menu_item_id", a field that > > doesn't exist. > > If I tried ordering = ('menu_item') then the Admin interface bombed > out due to broken SQL - the ORDER BY referenced the menu_item table > but it was not in the FROM clause. > > I considered the 'order_with_respect_to' option, but it would appear > to serve some other function (although I'm not sure exactly what that > is...) > > So, my questions a) Is this a bug or am I missing something and b) If > this is a bug would the correct solution be to patch the manager to > accept _id in ordering or patch the SQL query to use the correct tables? > > Thanks, > > James
There was a simmilar question a couple of days ago: On Mar 31, 7:14 am, Gilhad <[EMAIL PROTECTED]> wrote: > I have something like this: > > class Project(models.Model): > name = models.CharField(maxlength=10) > order = models.IntegerField() > .... > def __str__(self): return self.name > > class Task(models.Model): > project = models.ForeignKey(Project) > description = models.CharField(maxlength=100) > > Is there a way in Admin, when editing Task, to have the Select field for > Project sorted by Project.order (or at least by Project.name) instead of > Project.id? > > (The Project.id order looks pretty chaotic, as it reflex the time (id is > AutoField), when the Project was entered, which is surely not too much > descriptive, as many related Projects are entered at very different times) > > -- > Zdravi > Gilhad > [EMAIL PROTECTED] How about class Meta: ordering = ['name'] More info: http://www.djangoproject.com/documentation/0.95/model-api/#id5 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---