:)
On Apr 26, 9:48 am, Jim N wrote:
> Nick,
>
> Thanks very much. That worked! I can't work out why my code didn't
> though (or rather, worked twice).
>
> -Jim
>
> On Apr 23, 6:37 pm, Nick Serra wrote:
>
>
>
>
>
> > Try this out and see what happens:
>
> > def _hook_post_save_answer(instance,
Nick,
Thanks very much. That worked! I can't work out why my code didn't
though (or rather, worked twice).
-Jim
On Apr 23, 6:37 pm, Nick Serra wrote:
> Try this out and see what happens:
>
> def _hook_post_save_answer(instance, created, sender, **kwargs):
> if created:
> if instan
Try this out and see what happens:
def _hook_post_save_answer(instance, created, sender, **kwargs):
if created:
if instance.user:
quser = instance.user.get_profile()
quser.increment_answers()
instance.question.increment_responses()
post_save.connect(_ho
OK, that makes total sense.
I've implemented it like so:
def _hook_post_save_answer(instance, sender, **kwargs):
if 'created' in kwargs and kwargs['created'] == True:
if instance.user:
quser = instance.user.get_profile()
quser.increment_answers()
inst
I didn't even think of that. It's not very common to be specifying
pk's on create anyway, so yours would probably be fine. I just think
signals are cleaner and use them when I can :)
On Apr 23, 4:47 pm, Skylar Saveland wrote:
> Yeah, and I think my suggestion fails for a user-defined rather than
Yeah, and I think my suggestion fails for a user-defined rather than
auto-incrementing pk.
On Apr 23, 4:21 pm, Nick Serra wrote:
> A post save signal seems better suited for this. The post save signal
> has an attribute 'created' that will be true or false depending on if
> the object is being cr
A post save signal seems better suited for this. The post save signal
has an attribute 'created' that will be true or false depending on if
the object is being created or updated. Check out the post_save
documentation:
http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post
On Apr 23, 3:27 pm, Jim N wrote:
> Hi,
>
> I have overridden the default save() on a model so that I can update
> some counts every time a save occurs. Unfortunately, I don't want to
> perform these actions every time the model is updated, which seems to
> happen.
>
> Is there another approach
8 matches
Mail list logo