views.py 981 Bytes
from django.shortcuts import render
from django.db.models import Count
from .models import RT_edu, Maps, RT_agri_policy

# Create your views here.

def dbselect(contenttype, maptype):
    if maptype == 9:
        mapt = 'city'
    elif maptype == 10:
        mapt = 'cntr'

    if contenttype=='policy':
        myrtrn = RT_agri_policy.objects.values(mapt).annotate(count=Count(mapt))
        return myrtrn
    elif contenttype=='edu':
        myrtrn = RT_edu.objects.values(mapt).annotate(count=Count(mapt))
        return myrtrn

def main(request):
    return render(request, 'main.html')

def returnfarm(request, maptype):
    mapp = Maps.objects.get(id=maptype)
    mapp = mapp.mapdata
    exportdatas = dbselect('policy', maptype)
    context = {'exportdata': exportdatas, 'maps':mapp}
    return render(request, 'returnfarm.html', context)

def population(request):
    return render(request, 'population.html')

def market(request):
    return render(request, 'market.html')