| 13 | An example use case: |
| 14 | |
| 15 | {{{ |
| 16 | class Caller(models.Model): |
| 17 | callback = models.CharField() |
| 18 | max_attemps = models.IntegerField(default=1) |
| 19 | |
| 20 | def call(self): |
| 21 | call = Call(caller_ptr=self) |
| 22 | try: |
| 23 | call.execute() |
| 24 | except: |
| 25 | if self.max_attempts > Call.objects.filter(caller_ptr=self): |
| 26 | return self.call() |
| 27 | raise |
| 28 | return call.result |
| 29 | |
| 30 | class Call(Caller): |
| 31 | result = models.PickleField() |
| 32 | |
| 33 | def call(self): |
| 34 | self.result = import_string(self.callback)() |
| 35 | return self.result |
| 36 | }}} |
| 37 | |
| 38 | |