34👍
✅
The post_save
signal receives a boolean created
argument which indicates if the saved instance
was created.
def my_callback(sender, **kwargs):
if kwargs['created']:
print('Instance is new')
3👍
Take a look at https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save
There actually is an argument passed with the signal “created: A boolean; True if a new record was created”.
I think, that should do the trick.
- Django: how to change values for nullbooleanfield in a modelform?
- Django formset , queries for relational field for every form
- Django + Pydev/Eclipse + Google App Engine – possible?
0👍
Checking for instance.id is a nice way of determining if the instance is “new”. This only works if you use ids that are auto-generated by your database.
- How to add anchor to django url in template
- Django – How to filter by date with Django Rest Framework?
- Django template for loop
- Django template variable value to string literal comparison fails
Source:stackexchange.com