Domanda

I am using mezzanine + cartridge to make a shopping cart app.I want to call a customize function whenever admin change the order status from unprocessed to processed.

The customize function may includes sending mail, add track order no. etc.

But I don't know how to call this function on change of one field only and where to call this either admin.py OR models.py

Please give me some hint of whereIi made this and it calls only when one field changes in the database

È stato utile?

Soluzione

models.py:

class MyModel(models.Model):
    ...

    def save(self):
        super(DocumentTemplate, self).save(*args, **kwargs)

        # retrieve the old version of the object
        try:
           old = DocumentTemplate.objects.get(id=self.id)
        except MyModel.DoesNotExist:
           # object is being created
           customize_function_create(self)

        # check if something has changed
        if self.interesting_field != old.interesting_field:
            # the field has been changed
            customize_function_update(self)

        return
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top