Making an operation before and after a recording in the model.

4 views
Skip to first unread message

Bussiere

unread,
Jun 24, 2011, 4:20:17 AM6/24/11
to django...@googlegroups.com
Hello,
this is my first message here.
I have a question :

I have a actor object in my model, and a webpage in my model.

And i want that when a user record an actor in the admin interface it create automatically a webpage associated wit(h the actor.
I now how to create the webpage in my model, but i want to call a function each time someone record an actor in the administration menu.

How to do that please ?

Regards
Bussiere

Simone Dalla

unread,
Jun 24, 2011, 4:47:11 AM6/24/11
to django...@googlegroups.com


2011/6/24 Bussiere <buss...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/_RKcqS3uvZEJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

https://docs.djangoproject.com/en/1.3/topics/db/models/#overriding-model-methods

--
Simo

- Registered Linux User #395060

- Software is like sex, it is better when it is free  --> Linus B. Torvalds

Masklinn

unread,
Jun 24, 2011, 4:51:59 AM6/24/11
to django...@googlegroups.com
On 2011-06-24, at 10:47 , Simone Dalla wrote:
> 2011/6/24 Bussiere <buss...@gmail.com>
>
>> Hello,
>> this is my first message here.
>> I have a question :
>>
>> I have a actor object in my model, and a webpage in my model.
>>
>> And i want that when a user record an actor in the admin interface it
>> create automatically a webpage associated wit(h the actor.
>> I now how to create the webpage in my model, but i want to call a function
>> each time someone record an actor in the administration menu.
>>
>> How to do that please ?
>>
>> Regards
>> Bussiere
>>
>
> https://docs.djangoproject.com/en/1.3/topics/db/models/#overriding-model-methods
This creates a strong coupling between the model and a potentially unrelated business or maintenance operation.

Bussiere's use case seems to be exactly what signals[0] were included for, so I'd recommend that instead.

[0] https://docs.djangoproject.com/en/dev/topics/signals/

bussiere bussiere

unread,
Jun 24, 2011, 4:50:58 AM6/24/11
to django...@googlegroups.com
Thanks a lot i've watched the signals but this way is much much easier

Thanks a lot
Bussiere



"Les nouvelles technologies offrent pleins de nouvelles possibilités, pleins de possibilités d'erreurs surtout en fait."
insurance.aes256 : http://goo.gl/gHyAY




On Fri, Jun 24, 2011 at 10:47 AM, Simone Dalla <simo...@gmail.com> wrote:
t

bussiere bussiere

unread,
Jun 24, 2011, 4:57:19 AM6/24/11
to django...@googlegroups.com
Yes signals was a way to do it but it didn't clearly understood how it works.

Signals are interesting but i didn't manage to make them works for the moment.

But i will make more search on it.

Thanks and regards
Bussiere



"Les nouvelles technologies offrent pleins de nouvelles possibilités, pleins de possibilités d'erreurs surtout en fait."
insurance.aes256 : http://goo.gl/gHyAY




--
You received this message because you are subscribed to the Google Groups "Django users" group.

bruno desthuilliers

unread,
Jun 24, 2011, 6:15:56 AM6/24/11
to Django users
On Jun 24, 10:51 am, Masklinn <maskl...@masklinn.net> wrote:
> On 2011-06-24, at 10:47 , Simone Dalla wrote:
>
> > 2011/6/24 Bussiere <bussi...@gmail.com>
>
>>> And i want that when a user record an actor in the admin interface it
>>> create automatically a webpage associated wit(h the actor.
>>> I now how to create the webpage in my model, but i want to call a function
>>> each time someone record an actor in the administration menu.
>
>
> >https://docs.djangoproject.com/en/1.3/topics/db/models/#overriding-mo...
>
> This creates a strong coupling between the model

Which may OR NOT be a problem - there's nothing wrong with coupling
two classes when they're intended to work together.

@OP: if you use the first solution, the Actor class will depend on the
Webpage class. If you use the signal solution, Actor will not know
anything about Webpage, so you can later reuse Actor without Webpage.
Which solution is best really depends on your needs.

Also:

>>> And i want that when a user record an actor in the admin interface it
>>> create automatically a webpage associated with the actor.

Whether you override Actor.save or use a signal, a Webpage will be
created WHENEVER an Actor is created - even if it's not created thru
the admin interface. If you only want to have the webpage created when
the Actor is created thru the admin interface, you might be better
overriding the ActorAdmin.save_model method (https://
docs.djangoproject.com/en/1.3/ref/contrib/admin/
#django.contrib.admin.ModelAdmin.save_model). Note that you can have
your cake and eat it to: if you don't want to still use signals, you
can define your own signals in the app where's the Actor model is
defined, override ActorAdmin.save_model to just send your own custom
signal, and - in another app - connect a receiver for this signal that
will create the associated webpage.

HTH
Reply all
Reply to author
Forward
0 new messages