Thanks a lot, Tom, I think this is just what I need, I will try it asap and see which is better, between the two solutions.

Regards,
Hélène




On 21/05/2014 19:35, Tom Lockhart wrote:
On 2014-05-21, at 9:15 AM, chansonsyiddish <chansonsyidd...@gmail.com <mailto:chansonsyidd...@gmail.com>> wrote:

Thanks, Tom,

I'm not sure I need to use signals altogether, as I know when a Song is added. If I make a method in the Song model, I suppose I can import the model and run it in the shell? Or is there a way I could run it directly from the admin site?

Yes and yes.

python manage.py shell
>>> from yourapp.models import Song
>>> s = Song.objects.get(title='your title here')
>>> s.make_words()

For the admin interface, look at the actions keyword for admin classes. Something like

class SongAdmin(admin.ModelAdmin):
  ...
  actions = ['gen_words']
  ...
  def gen_words(self, request, queryset):
    for obj in queryset:
      obj.make_words()
      pass
    return
    gen_words.description='Generate words for selected songs'

To do the same for all songs at once you can implement a management command for the command line or if in the admin GUI you will likely want to implement a GUI button. I'd stayed away from GUI buttons previously but it turns out to be pretty simple once you have one done.

hth

                     - Tom



Hélène




On 21/05/2014 17:15, Tom Lockhart wrote:
On 2014-05-20, at 12:26 PM, "C. Kirby" <mist...@gmail.com <mailto:mist...@gmail.com>> wrote:

I would strongly suggest you use signals <https://docs.djangoproject.com/en/1.7/topics/signals/>.

This nicely enables an automatic path of execution. But if you also want to execute this code, say, from the admin interface or separately for testing then you may want to package the fundamental code into a method of the Song model, then run that method in the signal handler.

hth

                        - Tom



--
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 <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto: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/537CD10A.9070307%40gmail.com <https://groups.google.com/d/msgid/django-users/537CD10A.9070307%40gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

Please consider the environment before printing this message.
*/This message may be privileged and/or confidential, and the sender does not waive any related rights and obligations. Any distribution, use or copying of this message or the information it contains by other than an intended recipient is unauthorized. If you received this message in error, please immediately advise me by return e-mail or phone. All information, references, images, programs, source code, or other materials whatsoever contained in, or supplied with, this document are TRADE SECRETS and governed by the Uniform Trade Secrets Act. User assumes all direct and consequential liabilities and costs that result from any unauthorized disclosure or use of this information./*

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/z416rzZ8Ih8/unsubscribe. To unsubscribe from this group and all its topics, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto: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/75348526-0BC0-4153-B1C9-2DCEA95F3282%40gmail.com <https://groups.google.com/d/msgid/django-users/75348526-0BC0-4153-B1C9-2DCEA95F3282%40gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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/537CEC37.4060502%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to