On Tue, Nov 27, 2012 at 11:16 AM,  <jirka.vejra...@gmail.com> wrote:
> I may se the formating incorrectly (on a phone) but it looks like your save() 
> method does nothing if self.pk already exists (i.e. model is not new)

You are right, quite embarrassing. But it does work in other contexts.

Everyday I learn something new about Django and think I'm getting
better, everyday it puts me back in my place :)

cheers
L.

>
>   HTH
>
>     Jirka
>
> -----Original Message-----
> From: Lachlan Musicman <data...@gmail.com>
> Sender: django-users@googlegroups.com
> Date: Tue, 27 Nov 2012 11:07:42
> To: <django-users@googlegroups.com>
> Reply-To: django-users@googlegroups.com
> Subject: Re: Confused about model save/update
>
> On Tue, Nov 27, 2012 at 11:00 AM,  <jirka.vejra...@gmail.com> wrote:
>> Hi there,
>>
>>   a long shot since you have not provided your save() method. Are you 
>> calling super() there?
>
> Jirka, yes I am, but it's only been modified to set the slug:
>
>     def save(self, *args, **kwargs):
>         if not self.pk:
>             super(Applicant, self).save(*args, **kwargs) # Call the
> first save() method to get pk
>             self.slug = slugify(str(self))
>             super(Applicant, self).save(*args, **kwargs) # Call the
> "real" save() method.
>
>
> Cheers
> L.
>
>>
>>   Cheers
>>
>>      Jirka
>>
>> -----Original Message-----
>> From: Lachlan Musicman <data...@gmail.com>
>> Sender: django-users@googlegroups.com
>> Date: Tue, 27 Nov 2012 10:14:03
>> To: <django-users@googlegroups.com>
>> Reply-To: django-users@googlegroups.com
>> Subject: Confused about model save/update
>>
>> Hi
>>
>> Sorry about the last email - fat fingered it.
>>
>> For some reason I can't get the model.save() method to actually save
>> the data I want it to. I have tried using both save() and
>> save(force_update=True) without any joy.
>>
>> I have the following model:
>>
>> class Applicant(model.Models):
>> ...
>> successful = NullBooleanField()
>> ...
>>
>> def mark_successful(self):
>>    self.successful = 0
>>    self.last_change_by = request.user
>>    #self.save(force_update=True)
>>    self.save()
>>
>> def mark_successful(self):
>>    self.successful = 1
>>    self.last_change_by = request.user
>>    self.save(force_update=True)
>>    self.save()
>>
>>
>> I call these functions from the admin interface, via admin.py:
>>
>> class ApplicantAdmin(admin.ModelAdmin):
>> ...
>> actions = ['mark_successful', 'mark_unsuccessful']
>> ...
>>
>> def mark_unsuccessful(self, request, queryset):
>>         '''Marks a group of applicants as unsuccessful'''
>>         rows_updated = 0
>>         for applicant in queryset:
>>             applicant.mark_unsuccessful(request)
>>             rows_updated += 1
>>
>>         if rows_updated == 1:
>>             message_bit = "1 applicant was"
>>         else:
>>             message_bit = "%s applicants were" % rows_updated
>>         self.message_user(request, "%s marked unsuccessful." % message_bit)
>>
>>
>>
>> Can anyone see what's going wrong?
>>
>> cheers
>> L.
>>
>> --
>> ...we look at the present day through a rear-view mirror. This is
>> something Marshall McLuhan said back in the Sixties, when the world
>> was in the grip of authentic-seeming future narratives. He said, “We
>> look at the present through a rear-view mirror. We march backwards
>> into the future.”
>>
>> http://www.warrenellis.com/?p=14314
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> ...we look at the present day through a rear-view mirror. This is
> something Marshall McLuhan said back in the Sixties, when the world
> was in the grip of authentic-seeming future narratives. He said, “We
> look at the present through a rear-view mirror. We march backwards
> into the future.”
>
> http://www.warrenellis.com/?p=14314
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>



--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to