Tuesday, March 4, 2014

Admin interface is calling a custom method on my model?

I have a model with a custom method like so:

class MyModel(models.Model):
    some_counter_field = models.IntegerField(blank=True, default=0)

    def my_custom_method(self):
        if (self.some_counter_field < 5):
            self.some_counter_field += 1
            self.save()
            return True
        else:
            return False

The only place this method is called is in one of my templates.

I was using the Django Admin interface to facilitate testing this, so I could easily reset some_counter_field back to 0. However, I noticed that just by viewing an instance of this model in the admin interface was causing some_counter_field to be incremented until it hit 5. What is also strange is that this only happens in production, I was not able to reproduce this with my local runserver, even when I had DEBUG=False like production has.

Any ideas as to what might be going on here?

Thanks!
Greg

--
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+unsubscribe@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/1050ca2f-c945-4490-b9ae-e3e6b6cc83b6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment