Ticket #4879: post_save_with_created_kw.patch

File post_save_with_created_kw.patch, 1.1 KB (added by gav@…, 17 years ago)

Adds a "created" flag to the post_save signal.

  • django/db/models/base.py

    old new class Model(object):  
    241241                placeholders.append('(SELECT COUNT(*) FROM %s WHERE %s = %%s)' % \
    242242                    (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.order_with_respect_to.column)))
    243243                db_values.append(getattr(self, self._meta.order_with_respect_to.attname))
     244            record_exists = False
    244245            if db_values:
    245246                cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
    246247                    (backend.quote_name(self._meta.db_table), ','.join(field_names),
    class Model(object):  
    256257        transaction.commit_unless_managed()
    257258
    258259        # Run any post-save hooks.
    259         dispatcher.send(signal=signals.post_save, sender=self.__class__, instance=self)
     260        dispatcher.send(signal=signals.post_save, sender=self.__class__, instance=self, created=(not record_exists))
    260261
    261262    save.alters_data = True
    262263
Back to Top