order - Django TypeError unsupported operand type(s) for +: 'dict' and 'int' -


i created through model can add order field m2m field having problems auto incrementing order field via def number() below. when add object, typeerror unsupported operand type(s) +: 'dict' , 'int' , i'm not sure why. ideas?

models.py:

class playlist(models.model):     user = models.foreignkey(settings.auth_user_model, default=1)     name = models.charfield(max_length=50)     tracks = models.manytomanyfield(track, through='playlisttrack')      def __str__(self):         return self.name  class playlisttrack(models.model):      def number():         last_order = playlisttrack.objects.all().aggregate(max('order'))         if last_order == none:             return 1         else:             return last_order + 1      track = models.foreignkey(track)     playlist = models.foreignkey(playlist)     order = models.positiveintegerfield(default=number)      class meta:         ordering = ['order'] 

as mentioned in docs, aggregate() returns dict object. hence, variable last_order dict , trying add number dict.

you should value dict , add.

return last_order['order__max'] + 1 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -