Created
May 8, 2018 20:48
-
-
Save rg3915/858976c11bd626f78f2e43b5d02890cd to your computer and use it in GitHub Desktop.
Annotate, JSON parse and ChartJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gomakethings.com/decoding-html-entities-with-vanilla-javascript/ | |
var decodeHTML = function(html) { | |
var txt = document.createElement('textarea') | |
txt.innerHTML = html | |
return txt.value | |
} | |
var string = "{{ job_per_recruter }}" | |
var array = JSON.parse(decodeHTML(string)) | |
console.log(array); | |
// Criando dois arrays | |
array_job_hiring.forEach(function(item) { | |
mylabel.push(item.label) | |
myvalue.push(item.value) | |
}) | |
console.log(mylabel); | |
console.log(myvalue); | |
// Ou | |
var titulo = array_job_hiring.map(function(item) {return item.label}) | |
var valor = array_job_hiring.map(function(item) {return item.value}) | |
console.log(titulo); | |
console.log(valor); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Vagas Abertas por Recrutador | |
data = Job.objects.filter(creator__in=emp)\ | |
.values('recruiter')\ | |
.annotate(value=Count('recruiter'))\ | |
.order_by('recruiter')\ | |
.values('recruiter__first_name', 'value') | |
''' | |
Precisa reescrever o dicionário com os campos do gráfico, | |
que são: 'label' e 'value'. | |
''' | |
lista = [ | |
{ | |
'label': item['recruiter__first_name'], | |
'value': item['value'], | |
} | |
for item in data | |
] | |
job_per_recruter = json.dumps(lista, cls=DjangoJSONEncoder) | |
context['job_per_recruter'] = job_per_recruter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment