Re: using return upper
Hello, I found a solution for the simplified version of my problem. In models.py, I use: def __unicode__(self): oses_installed = u','.join(self.operatingsystemused.all().values_list('operatingsystem', flat=True)) return ("%s" % (oses_installed)) However, it doesn't works in admin.py Following lines give me (None): def renvoi_os(maintenance): oses_installed = u','.join(maintenance.ordi.operationsystemused_set.all().values_list('operatingsystem',flat=True)) return ("%s" % (oses_installed)) class MaintenanceAdmin(admin.ModelAdmin): list_display = (renvoi_os,) Thanks for your help On 2 fév, 03:31, Rainy wrote: > On Feb 1, 6:12 pm, makayabou wrote: > > > > > Hello, > > I try to simplify the problem. > > > This model gives me a (None) result: > > > class OperatingSystem (models.Model): > > operatingsystem = CharField (max_length=30, blank=True, null=True) > > def __unicode__(self): > > return "%s" % (self.operatingsystem) > > class Ordi(models.Model): > > architecture = CharField (max_length=30, blank=True, null=True) > > operatingsystemused = ManyToManyField(OperatingSystem, null=True, > > blank=True) > > > def __unicode__(self): > > oses_installed = > > u','.join(self.operationsystemused_set.all().values('operatingsystem',flat= > > True)) > > return ("%s" % (oses_installed)).upper() > > > Or also the same with that last line: > > > return models.join(list(self.operatingsystemused)) > > > What can I do?? > > > thanks > > How about > self.operatingsystemused.all().values('operatingsystem',flat= True) > > -ak -- 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.
Re: using return upper
On Feb 1, 6:12 pm, makayabou wrote: > Hello, > I try to simplify the problem. > > This model gives me a (None) result: > > class OperatingSystem (models.Model): > operatingsystem = CharField (max_length=30, blank=True, null=True) > def __unicode__(self): > return "%s" % (self.operatingsystem) > class Ordi(models.Model): > architecture = CharField (max_length=30, blank=True, null=True) > operatingsystemused = ManyToManyField(OperatingSystem, null=True, > blank=True) > > def __unicode__(self): > oses_installed = > u','.join(self.operationsystemused_set.all().values('operatingsystem',flat= > True)) > return ("%s" % (oses_installed)).upper() > > Or also the same with that last line: > > return models.join(list(self.operatingsystemused)) > > What can I do?? > > thanks How about self.operatingsystemused.all().values('operatingsystem',flat= True) -ak -- 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.
Re: using return upper
Hello, I try to simplify the problem. This model gives me a (None) result: class OperatingSystem (models.Model): operatingsystem = CharField (max_length=30, blank=True, null=True) def __unicode__(self): return "%s" % (self.operatingsystem) class Ordi(models.Model): architecture = CharField (max_length=30, blank=True, null=True) operatingsystemused = ManyToManyField(OperatingSystem, null=True, blank=True) def __unicode__(self): oses_installed = u','.join(self.operationsystemused_set.all().values('operatingsystem',flat=True)) return ("%s" % (oses_installed)).upper() Or also the same with that last line: return models.join(list(self.operatingsystemused)) What can I do?? thanks -- 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.
Re: using return upper
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 wrote: > On Tue, Feb 1, 2011 at 10:32 AM, makayabou 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.
Re: using return upper
On Tue, Feb 1, 2011 at 10:32 AM, makayabou 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.
using return upper
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,) #class OrdiAdmin(admin.ModelAdmin): admin.site.register(Ordi) admin.site.register(Maintenance,MaintenanceAdmin) admin.site.register(OperatingSystem) That admin.py is associated with this models.py: from django.db import models from django.db.models import (Model, BooleanField, CharField, DateTimeField, TextField, URLField, EmailField, ManyToManyField, ForeignKey, IntegerField, FileField, ImageField) # Create your models here. class OperatingSystem (models.Model): operatingsystem = CharField (max_length=30, blank=True, null=True) class Ordi(models.Model): architecture = CharField (max_length=30, blank=True, null=True) operatingsystemused = ManyToManyField(OperatingSystem, null=True, blank=True) class Maintenance(models.Model): ordi=ForeignKey(Ordi, blank=True, null=True) action = TextField(null=True, blank=True) When I just call Ordi.id in admin.py (commented line), I get the Ordi id associated with "Maintenance". But the line with Ordi.id + Ordi.operatingsystemused gives me back a (None) What am I doing wrong?? THanks for your help Florian -- 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.