Hi all. I am trying to figure it out but I am unable to do so and I am stuck.
My requirement is that I want to know how to get the name of any user from the django model - django.contrib.auth.models.User, and doing this only solely on the basis of ID. I also want to delete the user in case I choose to do so, hence I'm trying to use this to do it:
User.objects.get(id=request.POST['id'])
The thing is it returns a straight-up error and I am presen
User matching query does not exist.
Do note that in this case I am using the ID which is sent by AJAX:
$("#dynamic-table").on('click','.member_delete_btn', function() {
if (confirm("Are you sure? the member will be deleted...") == true) {
$.ajax({
type: "POST",
url: "/panel/member/delete/",
data: { id: $(this).attr('data-id'), 'csrfmiddlewaretoken': '{{ csrf_token }}' },
success: function (data) {
if(data.success) {
$('#result').html('<div class="alert alert-success"> <strong>Well done!</strong> Member deleted.</div>');
list_members();
}else{
$('#result').html('<div class="alert alert-warning"> <strong>Warning!</strong> Member not deleted.</div>');
}
},
error: function (data) {
alert("failure:" + data.error);
}
});
}
else {
return false;
}
return false;
});
But where I am confused is that when I go ahead and debug it it seems to be perfectly alright, the user actually exists in the database tables and the other thing is that the ID is perfect and intact (correct)
So my question is simple, how do I do this? Is there any particular delete method meant solely for Django User instances? Or how I go about this on a whole?
Appreciate all the help, thanks!