Hi everyone. I'm a newbie in Django and I would like to have your assistance. I have wrote a Django code that would allow the authenticated user to submit SQL script file and the contents of the script will be SQL injection protected, SQL Linted, encoded in base64 and saved as text in the Database. I would like to know I can implement the feature to list all the SQL scripts that have been submitted by the authenticated user.
Below is the code I wrote
models.py
from django.db import models
class DashboardSQLUpload(models.Model):
project_name = models.CharField(max_length=100)
notes = models.TextField(null=True, blank=True, max_length=500)
ENVIRONMENT_CHOICES = [
('QA','QA Env'),
('PROD', 'PROD Env'),
]
environment = models.CharField(max_length=4, default='QA', choices=ENVIRONMENT_CHOICES, blank=True, null=True)
sql_script_text_area = models.TextField(null=True, blank=True)
def __str__(self):
return (f"{self.project_name} - {self.environment}")
from django import forms
from .models import DashboardSQLUpload
class DashboardSqlUploadForm(forms.ModelForm):
upload_sql_script_file = forms.FileField(required=True, widget=forms.FileInput(attrs={'accept':'.sql','placeholder':'SQL Script File','class': 'form-control'}))
class Meta:
model = DashboardSQLUpload
fields = ['project_name', 'notes', 'environment']
exclude = ['sql_script_text_area']
widgets = {
'project_name': forms.TextInput(attrs={'placeholder':'Project Name','class': 'form-control'}),
'notes': forms.Textarea(attrs={'placeholder':'Notes',"rows":"3",'class': 'form-control'}),
'environment': forms.Select(attrs={'placeholder':'Environment','class': 'form-control'}),
}