If you allow Null values in your model and one of the two is being populated with Null, then you'll get the error you're seeing. Example:
Form: ram_1 = 56 ram_2 = Null (None) 56 + Null (None) doesn't work. What you should do instead is set Null to FALSE in both your field declarations and set a default value (it could be zero if you want, but since you have two choices, you can make it one of the two as well). You could leave it as null=True and set a default value, but that seems like bad practice. Bill On Mon, Apr 13, 2015 at 4:07 PM, makayabou <makaya...@gmail.com> wrote: > It's ram_tot = self.ram_1 + self.ram_2 > > that returns me "cannot contenate int and NOne > > On Monday, April 13, 2015 at 10:05:49 PM UTC+2, makayabou wrote: >> >> Hello, >> I'm sorry for that trivial problem, but I'm still a bit lost... >> >> [code] >> #In models.py: >> >> class Ordi(models.Model): >> RAM_CAP_1 = 1024 >> RAM_CAP_2 = 2048 >> RAM_CAP_CHOICES = ( >> (RAM_CAP_1, u'1G'), >> (RAM_CAP_2, u'2G'), >> ) >> ram_1 = models.IntegerField("memory slot 1", max_length=10, >> choices=RAM_CAP_CHOICES, null= True, blank=True) >> ram_2 = models.IntegerField("memory slot 2", max_length=10, >> choices=RAM_CAP_CHOICES, null= True, blank=True) >> >> def ram_total(self): >> ram_tot = self.ram_capacite_1 + self.ram_capacite_2 >> # >> # Here, python can't contenate int and NoneType... >> # >> return ram_tot >> def maintenus(self): >> ordis_maintenus = self.maintenance_set.all() >> for o in ordis_maintenus: >> return o.__unicode__ >> def __unicode__(self): >> return 'ordi '+unicode(self.id)+' - '+self.renvoios() >> >> >> class Maintenance(models.Model): >> ordi = models.ForeignKey(Ordi) >> def __unicode__(self): >> return self.titre + " du " +self.date_sortie.strftime('%m/%d/%Y') >> >> [/code] >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/f30ef94f-55b4-482f-9b39-a007e99321ff%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/f30ef94f-55b4-482f-9b39-a007e99321ff%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP7uEDLOp95VocH73Tx74LV7OMQmWHAsoAKErPBipC%3D_GxKGNQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.