-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logic in Views and Forms then Integrate Ajax
- Loading branch information
1 parent
5101e88
commit 0e01efd
Showing
12 changed files
with
287 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const qrForm = document.querySelector("#qr-form") | ||
const qrUrl = document.querySelector("#qr-url") | ||
const formCSRF = document.getElementsByName("csrfmiddlewaretoken") | ||
const qrImage = document.getElementById("qr-image") | ||
const qrDownload = document.getElementById("qr-download") | ||
|
||
|
||
console.log(qrDownload.href) | ||
qrForm.addEventListener("submit", (e)=>{ | ||
e.preventDefault(); | ||
const form = new FormData(); | ||
form.append('csrfmiddlewaretoken', formCSRF[0].value); | ||
form.append('url', qrUrl.value) | ||
|
||
$.ajax({ | ||
type:'POST', | ||
url:'/create_request', | ||
data:form, | ||
success:function(response){ | ||
qrImage.classList.remove('display') | ||
qrDownload.classList.remove('display') | ||
qrImage.src = response.qr | ||
qrDownload.href = response.qr | ||
}, | ||
error:function(error){ | ||
console.log(error) | ||
}, | ||
cache:false, | ||
contentType:false, | ||
processData:false, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django import forms | ||
|
||
from .models import QRCode | ||
|
||
|
||
class QRCodeForm(forms.ModelForm): | ||
class Meta: | ||
model = QRCode | ||
fields = ['url'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.3 on 2023-07-28 12:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('qrCodes', '0004_alter_qrcode_url'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='qrcode', | ||
name='url', | ||
field=models.CharField(max_length=250), | ||
), | ||
] |
Oops, something went wrong.