Home > Mobile >  How to get the entity after form.save()
How to get the entity after form.save()

Time:11-02

I have form class which receive the POST request from web browswer.

class WaveFileForm(forms.ModelForm):
    class Meta:
        model = WaveFile
        fields = ('description', 'document', )

then it will be saved as model entity by form.save()

if request.method == 'POST':
    form = WaveFileForm(request.POST, request.FILES)
    if form.is_valid():
        form.save()
        print(form.cleaned_data.get('document'))// it returns filename, but I want to have saved file path, so I want entity itself
        WaveFile.objects.get("(saved_one)")

But now I want to get the entity immediatelly it self which is saved by form.save()

How can I do this??

CodePudding user response:

form.save() will return the instance, so:

wave_file = form.save()
  • Related