Hello, With your stuff, it still shows me (None). You are right, Ordi means Ordinateur (computer)
Florian On 1 fév, 13:40, Tom Evans <tevans...@googlemail.com> wrote: > On Tue, Feb 1, 2011 at 10:32 AM, makayabou <makaya...@gmail.com> wrote: > > Hello, > > I'm trying to modify my admin.py from my app "ordis": > > > from ordis.models import Ordi, Maintenance, OperatingSystem > > from django.contrib import admin > > > #class MaintenanceAdmin(admin.ModelAdmin): > > #list_display = (???) here I would like to see my Computer id, and > > the OS installed on it > > > def renvoi_os(Ordi): > > #return ("%d" % (Ordi.id)).upper() > > return ("%d %d" % (Ordi.id, Ordi.operatingsystemused)).upper() > > class MaintenanceAdmin(admin.ModelAdmin): > > list_display = (renvoi_os,) > > The function renvoi_os seems to take an 'Ordi' (ordinateur?) object, > but you have associated it with MaintenanceAdmin, which is associated > with Maintenance, not an Ordi, so the renvoi_os function will raise an > exception when you attempt to access the 'operatingsystemused' > attribute, which exists on Ordi instances, not Maintenance instances. > > Further more, 'operatingsystemused' is not a simple attribute of Ordi, > its a ManyToMany, which you are trying to display as a decimal number > ('%d' in your format string). > > This should work: > > def renvoi_os(maintenance): > oses_installed = u', > '.join(maintenance.ordi.operationsystemused_set.all().values('operatingsystem', > flat=True)) > return ("%d %s" % (maintenance.ordi.id, oses_installed)).upper() > > class MaintenanceAdmin(admin.ModelAdmin): > list_display = (renvoi_os,) > > Cheers > > Tom -- 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.