I got a model containing two counters :
class MyObject(models.Model): ... student_c = models.PositiveIntegerField(default=0, blank=True, null=True) company_c = models.PositiveIntegerField(default=0, blank=True, null=True) def total_followers(self): return self.student_c + self.company_c
one is working perfectly and returns an integer value but the other one returns :
django.db.models.expressions.ExpressionNode object at 0x7ff4d8320a10
I tried to change PositiveIntegerField to IntegerField and to rename the field with another name but I still get the same result ? I destroyed the database and rebuilt it many times
In my template I can see this : (+: (DEFAULT: ), 1)
In fact I'm trying to do an atomic increment like this:
project = get_object_or_404(Project, pk=kwargs['pk'])
project.student_c = F('student_c') + 1
project.save(update_fields=['student_c']) or even just project.save()
This is where the problem is coming from. I looked there and I found the same code : Atomic increment of a counter in django
What am I doing wrong ?
Any help would be very appreciated.
Thanks