Re: Call a custom python function during each model save

2009-09-02 Thread Andy Mikhailenko

Try signals[1], namely pre_save[2]. I would stick to this way instead
of overriding model's save() method.

[1] http://docs.djangoproject.com/en/dev/topics/signals/
[2] 
http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save

On Sep 1, 4:21 pm, Harish  wrote:
> Hi Friends,
>
> I want to call a python function, while saving each model... How can I
> do this?
>
> For example I have many application in a project
> I have field in each model of the application and  I have to access
> the field just before the any model object is saved and alter a value
> of that field. Here I can use save_model() function, but I want to
> write a function once and each time when the model is saved that
> function should be called
>
> Any Idea for this...
>
> Regards
> Harish Bhat M
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Call a custom python function during each model save

2009-09-01 Thread ankit rai
def save_model(self, request, obj, form, change):
 obj.save()
   urfunction(aa,aa,aa,a)


On Tue, Sep 1, 2009 at 3:59 PM, ANIL KARADAĞ  wrote:

> you can override model save method:
>
> for example
>
> class Student(models.Model):
> name = models.CharField(blabla)
>
> def save(self, *force_insert=False*, *force_update=False*):
> # call spesific python method
> # operations
> super(Student, self).save(force_insert=force_insert,
> force_update=force_update)
>
>
> 2009/9/1 Harish 
>
>>
>> Hi Friends,
>>
>> I want to call a python function, while saving each model... How can I
>> do this?
>>
>> For example I have many application in a project
>> I have field in each model of the application and  I have to access
>> the field just before the any model object is saved and alter a value
>> of that field. Here I can use save_model() function, but I want to
>> write a function once and each time when the model is saved that
>> function should be called
>>
>> Any Idea for this...
>>
>>
>> Regards
>> Harish Bhat M
>>
>>
>
>
> --
> Anıl KARADAĞ
> Cihan Information S.C. - Software Development Engineer
> GYTE- Computer Engineer. - Master student
> http://anilkaradag.info/blog
>
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Call a custom python function during each model save

2009-09-01 Thread ankit rai
just overide save method
and inside that method call ur function ,*do import it *

for ex

def save_model():
  call ur function here

  myfunction(xx,aaa,aa)
  obj.save()



On Tue, Sep 1, 2009 at 3:59 PM, ANIL KARADAĞ  wrote:

> you can override model save method:
>
> for example
>
> class Student(models.Model):
> name = models.CharField(blabla)
>
> def save(self, *force_insert=False*, *force_update=False*):
> # call spesific python method
> # operations
> super(Student, self).save(force_insert=force_insert,
> force_update=force_update)
>
>
> 2009/9/1 Harish 
>
>>
>> Hi Friends,
>>
>> I want to call a python function, while saving each model... How can I
>> do this?
>>
>> For example I have many application in a project
>> I have field in each model of the application and  I have to access
>> the field just before the any model object is saved and alter a value
>> of that field. Here I can use save_model() function, but I want to
>> write a function once and each time when the model is saved that
>> function should be called
>>
>> Any Idea for this...
>>
>>
>> Regards
>> Harish Bhat M
>>
>>
>
>
> --
> Anıl KARADAĞ
> Cihan Information S.C. - Software Development Engineer
> GYTE- Computer Engineer. - Master student
> http://anilkaradag.info/blog
>
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Call a custom python function during each model save

2009-09-01 Thread ANIL KARADAĞ
you can override model save method:

for example

class Student(models.Model):
name = models.CharField(blabla)

def save(self, *force_insert=False*, *force_update=False*):
# call spesific python method
# operations
super(Student, self).save(force_insert=force_insert,
force_update=force_update)


2009/9/1 Harish 

>
> Hi Friends,
>
> I want to call a python function, while saving each model... How can I
> do this?
>
> For example I have many application in a project
> I have field in each model of the application and  I have to access
> the field just before the any model object is saved and alter a value
> of that field. Here I can use save_model() function, but I want to
> write a function once and each time when the model is saved that
> function should be called
>
> Any Idea for this...
>
>
> Regards
> Harish Bhat M
> >
>


-- 
Anıl KARADAĞ
Cihan Information S.C. - Software Development Engineer
GYTE- Computer Engineer. - Master student
http://anilkaradag.info/blog

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---