Tuesday, May 26, 2020

Re: Issue with CRUD Operation

To clear your form after submit, just re-assign an empty form object after the form.save(). See below

def soapprod_form (requestid=0):
    if request.method == "GET":
        if id == 0:
            form = SoapprodForm()
        else:
            soapprod = Soapprod.objects.get(pk=id)
            form = SoapprodForm (instance=soapprod)
        return render(request, "soapprod_form.html", {'form': form})
    else:
        if id == 0:
            form = SoapprodForm(request.POST)
        else:
            soapprod = Soapprod.objects.get(pk=id)
            form = SoapprodForm(request.POST,instance= soapprod)
        if form.is_valid():
            form.save()
            form = SoapprodForm()
        return render(request, "soapprod_form.html", {'form': form})

On Tue, May 26, 2020 at 8:07 AM Luqman Shofuleji <luqmanshof@gmail.com> wrote:
Hi,

Please also attach the code of your list template where the delete is been executed.

On Mon, May 25, 2020 at 1:39 AM Ifeanyi Chielo <ifeanyi.chielo@unn.edu.ng> wrote:
Hello,
I performed a CRUD operation and every thing is working well except two things
1. my insert form does not clear the text boxes after saving a record
2. my delete operation renders an error page after deleting a record with a message ''DoesNotExist at /delete/3/" or "AttributeError at /delete/6/" 
example of the error messages are  shown below. i also attached view.py, model.py and template file

DoesNotExist at /delete/3/

Soapprod matching query does not exist.

Request Method:

POST

Request URL:

http://localhost:8000/delete/3/

Django Version:

2.1.5

Exception Type:

DoesNotExist

Exception Value:

Soapprod matching query does not exist.

Exception Location:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\models\query.py in get, line 399

Python Executable:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\python.exe

Python Version:

3.7.2

Python Path:

['C:\\Users\\IFEANYI CHIELO\\divinecrown',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']

Server time:

Mon, 25 May 2020 00:03:25 +0000


or


AttributeError at /delete/6/

'str' object has no attribute 'get'

Request Method:

POST

Request URL:

http://localhost:8000/delete/6/

Django Version:

2.1.5

Exception Type:

AttributeError

Exception Value:

'str' object has no attribute 'get'

Exception Location:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\lib\site-packages\django\middleware\clickjacking.py in process_response, line 26

Python Executable:

C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\python.exe

Python Version:

3.7.2

Python Path:

['C:\\Users\\IFEANYI CHIELO\\divinecrown',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib',

 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37',

 'C:\\Users\\IFEANYI '

 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']

Server time:

Mon, 25 May 2020 00:09:23 +0000

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b43b280d-ab19-4620-8544-133c897396f0%40googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHyB84qbzBMJM7VmPSvvVrMy5QW0ku1mmBVY4RdDrZxjYYdu0w%40mail.gmail.com.

No comments:

Post a Comment