Home > Software engineering >  Django - class CreateView, how can I launch special function after success?
Django - class CreateView, how can I launch special function after success?

Time:03-28

I have a form, where user can type song_name and upload .wav file

in my views.py:

from django.views.generic import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from .forms import AudioCompositionForm

class AddAudio(LoginRequiredMixin, CreateView):
    form_class = AudioCompositionForm
    template_name = 'audio_test/add_audio.html'

I have a special function which convert wav to mp3 How can I launch this function after success upload? Will be ideal if i can transfer a new object <class 'audio_test.models.AudioComposition'> into in my audio_convert funcion. Thanks

CodePudding user response:

You can use the post_save signal at your model. https://docs.djangoproject.com/en/3.2/ref/signals/#post-save

CodePudding user response:

use form_valid for success upload

class AddAudio(LoginRequiredMixin, CreateView):
form_class = AudioCompositionForm
template_name = 'audio_test/add_audio.html'

def form_valid(self, form):
    # Everything you write here is related to success upload
  • Related