Hello, I am a beginner at Django!
I have a table where all the faculty data is shown, Here I have three models ( view ,edit,delete )
For view, I have created a $ajax call to grab the data from view
Here is the js code :
$(window).on("load",function(){
$(".edit-btn").on("click",function(){
var employee_id = $(this).attr('data-id');
$.ajax({
url: `/super-admin/people/faculty/getData/`+employee_id,
type: "GET",
success: (data) => {
console.log(data);
//Will populate the modal with the data
},
error: (error) => {
console.log(error);
}
});
})
})
and in the view.py I have used JSON response:
def facultyGetdata(request,id):
facultyData = all_faculty.objects.filter(id=id)
data = serializers.serialize('json',facultyData )
return JsonResponse({'data': facultyData},safe=False)
And ajax call is showing an error: Object of type QuerySet is not JSON serializable!
How can I make Django objects serialize?
Here is the model code, if it can be any help
class faculty(models.Model) :
name = models.TextField(max_length=100)
faculty_image = models.ImageField(null=True, blank=True, upload_to="Images/")
email = models.EmailField(max_length=50)
designation = models.TextField(max_length=100)
experience = models.TextField(max_length=100)
about = models.TextField(max_length=500, null=True)
url = models.TextField(max_length=100)
def __str__(self):
return self.name