[Answer]-Customize Django Admin Advice

1👍

This is quite a broad question but I’ll give it a shot.

There are a few ways you can achieve this:

Setting up a model with filter queries as variables.

models:

class Filter(models.Model):
    Filter_Query = models.CharField(max_length=30)

views:

from app_name.models import Filter, Some_Model

def filter(request, pk):
  template = loader.get_template("app_name/filter_search.html")
  filter_1 = Filter.objects.get(id=pk)  
  some_model = Some_Model.objects.all() 
  filter_1_search =  model_name.filter(some_option=filter_1)  
  context = RequestContext(request, {'filter_1_search': filter_1_search})
    return HttpResponse(template.render(context))

Then in a separate page, you can load the results like so.

{$("#some_div").load(filter/1)

or even easier you can you can just use AJAX to send whatever filter query you want.

views:

from app_name.models import Some_Model

def filter_query(request):
  filter_1 = request.GET.get('filter_query', '')# Receives from AJAX
  some_model = Some_Model.objects.all() 
  filter_1_search =  model_name.filter(some_option=filter_1)  
  jsonDump = json.dumps(str(filter_1_search))
     return HttpResponse(jsonDump, content_type='application/json') 

javascript:

var data_JSON_Request = {'filter_query': filter_search1, 'csrfmiddlewaretoken': "{{csrf_token}}"};//JSON package.

function ajax_call(data_JSON_Request){
  $(function jQuery_AJAX(){
    $.ajax({
      type: 'GET',
      url: '/filter_query/',
      data: data_JSON_Request,
      datatype: "json",
      success: function(data) {$("#sove_div").load(data);
            open_model_menu();
      },//success
      error: function() {alert("failed...");}
    });//.ajax
  });//jQuery_AJAX
};//ajax_call
👤DGDD

Leave a comment