Home:ALL Converter>Can not call model method in Django

Can not call model method in Django

Ask Time:2012-04-08T02:32:42         Author:You knows who

Json Formatter

I have a class in Django model.py

class Ticket(models.Model):
    game = models.ForeignKey(Game)

    def __unicode__(self):
        return self.numbers

    def checksum(self):
        #calculate checksum here

and in other function, I can call something like: ticket.checksum

But later, I add another method (get_scan)

class Ticket(models.Model):
    game = models.ForeignKey(Game)

    def __unicode__(self):
        return self.numbers

    def checksum(self):
        #calculate checksum here

    def get_scan(self):
        #calculate get_scan here

but now I can not call ticket.get_scan (eventhough ticket.checksum still works)

I have tried different way like restart web server, calling in Django shell ... but it does not work.

Error: 'Ticket' object has no attribute 'get_scan'

Updated: it's about indentation problem

Author:You knows who,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/10057182/can-not-call-model-method-in-django
yy