post save signal inline admin

2014-02-24 Thread Ali Rıza KELEŞ
Hi,

I have problem with post save signal.

Lets say we have two models Authors and Books. Authors model has a
post save signal: NotifyAuthor

When I save model Book with inline Author, Author's post save signal
does not work. If I save model Author via its own form, the signal
works properly.

Is there any quick / easy fix?

Thanks.

-- 
--
Ali Rıza Keleş

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALOKRKp4mwFM2EpoQMciptxV-Lwx%3DSzAqiWTnGDzjZ_76CP00g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Post-save hook after inline records saved?

2011-09-08 Thread Vinicius Massuchetto
On Feb 3 2010, 8:52 pm, Andy Robinson <captainro...@gmail.com> wrote:
> I'm writing a bookkeeping system using Django latest code.   I would
> like to make sure that when certain records are saved, changes are
> made to other records.    For example, when I save a Sale model in the
> admin - or programmatic code - it may create (or update) a bunch of
> records in the general ledger tables.  Overriding the model.save()
> method worked well up to a point.
>
> I have one model that uses inlines in a master-detail relationship.
> Think of Orders, and Lines within them.  I enter an Order with 3
> Lines.  Unfortunately, overriding Order.save() doesn't work, because
> when the save event fires, none of the lines have been saved or hooked
> up to it yet.     post-save signals are no better.
>
> (Ugly workaround in admin:  hit 'save and continue editing', then hit
> 'save'.  The second time I save, the order rows exist)
>
> Can anyone suggest a strategy whereby, when an Order gets saved, I can
> hook into some event AFTER the related Lines have been saved?

Hi Andy.

Did you find a workaround for this? Or can anyone suggest something
now?

Thanks
Vinicius Massuchetto

-- 
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: Post Save

2011-08-01 Thread Daniel Corbe
Thanks  already solved

i use post_save for child class and works for me!


On 1 August 2011 14:55, bruno desthuilliers
wrote:

> On 1 août, 19:17, Daniel Corbe  wrote:
> > Ok, halfly solved.
>
> What ?
>
> > The problem
>
> Which problem ?
>
> --
> 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.
>
>


-- 
Daniel Corbe Hahne Latorre
dan...@corbe.com.br
55 48 9618-5115
skype: daniel_corbe

-- 
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: Post Save

2011-08-01 Thread bruno desthuilliers
On 1 août, 19:17, Daniel Corbe  wrote:
> Ok, halfly solved.

What ?

> The problem

Which problem ?

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



Post Save

2011-08-01 Thread Daniel Corbe
Ok, halfly solved.
The problem is that post_save() for parent model doesn't calling for childs
models.
So you can solve it by providing child class directly.

class Advertisement(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
author_email = models.EmailField()

class Sale(Advertisement):
rooms = models.IntegerField(max_length=1)
subway = models.ForeignKey(Subway)

class Verification(models.Model):
advertisement = models.ForeignKeyField(Advertisement)
key = models.CharField(max_length=32)

def gen_key(sender, instance, created, **kwargs):
code goes here
post_save.connect(gen_key, sender=Sale, dispatch_uid="my_unique_identifier")

*So next question is "How can I use parent class for post_save()?"*

-- 
Daniel Corbe Hahne Latorre
dan...@corbe.com.br
55 48 9618-5115
skype: daniel_corbe

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



Post-save hook after inline records saved?

2010-02-03 Thread Andy Robinson
I'm writing a bookkeeping system using Django latest code.   I would
like to make sure that when certain records are saved, changes are
made to other records.For example, when I save a Sale model in the
admin - or programmatic code - it may create (or update) a bunch of
records in the general ledger tables.  Overriding the model.save()
method worked well up to a point.

I have one model that uses inlines in a master-detail relationship.
Think of Orders, and Lines within them.  I enter an Order with 3
Lines.  Unfortunately, overriding Order.save() doesn't work, because
when the save event fires, none of the lines have been saved or hooked
up to it yet. post-save signals are no better.

(Ugly workaround in admin:  hit 'save and continue editing', then hit
'save'.  The second time I save, the order rows exist)

Can anyone suggest a strategy whereby, when an Order gets saved, I can
hook into some event AFTER the related Lines have been saved?



Thanks,

Andy




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



0.96 admin inline - post-save on saved related items

2009-04-07 Thread Earthtalker

Hello -

I have a model called Category with a related model called Photos
pointing to it, and edited inline in the admin.
I have some processing I want to do after changes are saved for
Category and its related Photos items, but adding this code after super
(Category, self).save() doesn't seem to be working... I have to SAVE
AND CONTINUE EDITING, then SAVE again... I have tried accessing these
items as self.photos_set.all(), and as Photos.objects.filter
(category=self)... but nothing seems to work.

When are these related records saved in the admin as inline edited
items? How cat I get there?

Thanks very much... cheers!
- Thomas

--~--~-~--~~~---~--~~
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: Post Save Signal the best plan?

2009-03-11 Thread Alex Gaynor
On Wed, Mar 11, 2009 at 4:47 AM, Alfonso <allanhender...@gmail.com> wrote:

>
> Hi there,
>
> I've got a few tax calculations running on a custom save method within
> admin which work great but I need to build in the option to override
> these calculations manually.
>
> So I have 2 questions - is this what I'd use a post save method for
> (would I move the save calculations to a pre-save and add this manual
> override function to save method) and, is there a way to detect a
> manual change to a field in django?  A 'if not changed [manually] then
> do this' kind of concept?
>
> Thanks
> >
>
What I would do is overide save() and add an extra parameter
"dont_calculate" or something that is False by default but that you can pass
in when you don't want the calculations to occur.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Post Save Signal the best plan?

2009-03-11 Thread Alfonso

Hi there,

I've got a few tax calculations running on a custom save method within
admin which work great but I need to build in the option to override
these calculations manually.

So I have 2 questions - is this what I'd use a post save method for
(would I move the save calculations to a pre-save and add this manual
override function to save method) and, is there a way to detect a
manual change to a field in django?  A 'if not changed [manually] then
do this' kind of concept?

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



could not do post save functionality

2009-02-13 Thread gganesh

hi,
The post save functionality is not working fine  for me , please
rectify mu faults ,
i have tried 2 ways to access post save functionality but both failed
( shown below  as no :1 and no: 2 )

i case of no: 1
i got the o/p of line no 12 in the server but after saving ,line no 14
is not displayed in the server

i case of no 2:
i cannot understand whatis going on



from django.db import models
from django.db.models import signals

class Selector(models.Model):
selctor_name = models.CharField(max_length=200)
acct_number =  models.CharField(max_length=200,editable=False)

1.  def save(self):

11  self.acct_number= 'RBSA'
12  print "i have call save method here "
13  super(Selector, self).save()
14  print "i got the id the number is : ",self.id
15  self.acct_number += str(self.id)


2.  def after(instance, created, **kwargs):
   print '%s was just %s' % (instance, created and 'created'
or 'updated')
   print "i'ma inside after method now"
signals.post_save.connect(after, sender=Selector)


Sorry i am new to Django, just few weeks old
i hope i have conveyed my problem in a right way
thanks in advance
ganesh
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Any ideas why this code won't work in a post save signal, but will in the shell?

2008-12-03 Thread tenni

def post_save_user_handler(sender, **kwargs):
user = kwargs['instance']
if user.is_staff:
# only give add_staffprofile permissions to staff

p_add_perm = Permission.objects.get
(codename='add_staffprofile')
p_change_perm = Permission.objects.get
(codename='change_staffprofile')
try:
user.get_profile() # See if there is a profile already
(raises exception if there isn't)
except:
# user doesn't have a profile, give them add_staffprofile
permissions
if p_add_perm not in user.user_permissions.all():
user.user_permissions.add(p_add_perm)
else:
# user has a profile already, remove add_staffprofile and
add change_staffprofile
if p_add_perm in user.user_permissions.all():
user.user_permissions.remove(p_add_perm)
if p_change_perm not in user.user_permissions.all():
user.user_permissions.add(p_change_perm)
signals.post_save.connect(post_save_user_handler, sender=User) #
Hopefully User is setup by now...

###

I have a new user who is a staff member but doesn't have a profile
yet. Each time the user is edited (saved) I want to check if they are
still staff and if they have a profile created.

If they do, I want to remove their add_staffprofile permission and
give them a change_staffprofile permission instead.

If they don't have a profile, I want to make sure they have an
add_staffprofile permissions.

I can run this from the interactive prompt (python manage.py
runserver) and it works as expected (user gets add_staffprofile
permission). But when I save the user in the admin (as a staff member
without a profile) the permission is never added.

Thanks for any pointers...
Andrew.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



post-save hook in newforms-admin

2008-07-16 Thread Wanrong Lin

Hi,

I just switched to the newforms-admin branch. After some tweaking, 
things worked fine. But the real reason I switched is because I want to 
use the post-save hook in the new admin application. To be more 
specific, I want to perform some processing on a database entry after it 
is added or changed in the administration web site. I can not do it by 
overriding the "save" method, as it does not work right in the (old) 
admin application when M2M fields are involved. Now, my question is: 
where is this hook? I could not find it anywhere. Can someone show me? 
Thanks a lot.

Wanrong

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Post Save

2008-01-21 Thread Nathaniel Whiteinge

In the Django world (and the newspaper world), the canonical term for
what you're looking for is 'slug' and Django even has a built-in slug
model field [1].

If you're just using the built-in Admin, then it even has JavaScript
that will create the slug based on another model field.

However, if you need this functionality outside the Admin there are a
few options open to you:

The method defined in your model class that you were trying to recall
is documented at the bottom of the Model API docs [2]. This is an
excellent place to put this kind of functionality (you can even reuse
Django's built-in slugify functionality [3][4] that the Admin uses).
In fact, this is a fairly common use-case, you can browse how other
people have tried to solve this same problem by looking over the slug
tag on Django Snippets [5].

.. [1] http://www.djangoproject.com/documentation/model-api/#slugfield
.. [2] 
http://www.djangoproject.com/documentation/model-api/#overriding-default-model-methods
.. [3] http://www.djangoproject.com/documentation/templates/#slugify
.. [4] http://www.djangosnippets.org/snippets/43/
.. [5] http://www.djangosnippets.org/tags/slug/

Good luck! Let us know if you have further questions.
- whiteinge
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Post Save

2008-01-21 Thread Chris

I have a weblog that I am creating and it has a table with fields
called title and url_name.  I would like to make it possible for the
user to simply enter the title of the blog and then django would auto
format the url_name for me based off of the title. ex. - title = My
First Blog -->gets translated to --> url_name = my_first_blog.  I
recall something called _post_save(self): which is defined in your
models class but I am not sure how that would work for what I am
doing.  Anyone have any suggestions? or better way of doing this?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Pre/Post Save: Assigning a value to the attribute of a object???

2006-03-13 Thread [EMAIL PROTECTED]

Hi All,

I have a model something like this:

doctype_choices = (
('PDF','Adobe PDF'),
('WORD','Microsoft Word' ),
('EXCEL','Microsoft EXCEL'),

 )

sector_choices = (
('All','All'),
('Social Recovery','Social Recovery'),
('Physical Infrastructure','Physical Infrastructure'),
('Economic Recovery','Economic Recovery'),
('Finance and Administration','Finance and Administration'),
('Projects','Projects'),

)

class Document(meta.Model):
title = meta.CharField(maxlength=200)
description = meta.CharField(maxlength=300)
sector = meta.CharField(maxlength=200,choices=sector_choices)
document= meta.FileField(upload_to = "docs")
document_date = meta.DateField()
doctype = meta.CharField(maxlength=5,choices=doctype_choices)
docsize = meta.CharField(maxlength=10)



All I want to do is the get the size of a document ( stat/getsize()
whatever ) and save it as docsize in my database when the document is
saved in Admin.

Not sure how the pre_save() works, but I imagine that a post_save() may
do it?( not many practical examples of these in the tutorials though)

I must be missing something, but I am not seeing how this can be done
and I cannot recall seeing many examples of assigning a value to an
attribute of an object in the tutorials either.

Grateful for any input.

Django is great!!!

Y-Coci


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---