Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

546
Views
Django: ¿es posible pasar Model Enums a Template Javascript?

¿Es posible en Django pasar valores enumerados de un modelo?

Plantilla HTML de Django - JS en la parte inferior

Por ejemplo, ¿puedo en JS, hacer algo como

 `var enumValue1 = "{{employment_ukrightowork_form.right_to_work_selection.UKRightoWorkSelection.PASSPORT}}"

MODELO Django

Si mi modelo en model.py se ve así:

 # UK RIGHT TO WORK MODEL class UK_Right_To_Work(models.Model): class UKRightoWorkSelection(models.TextChoices): PASSPORT = 'Passport', _('UK or Irish - Passport') BIRTHCERT = 'Birth Certificate & NI Number', _('UK or Irish - Birth or Adoption Certificate + Proof of National Insurance Number') CERTOFREG = 'Certificate of Registration & NI Number', _('UK or Irish - Certificate of Registration or Naturalisation + Proof of National Insurance Number') right_to_work_id = models.BigAutoField(verbose_name='UK Right to Work ID', primary_key=True, serialize=False, auto_created=True) right_to_work_selection = models.CharField(verbose_name='UK Right to Work selection', max_length=41, choices=UKRightoWorkSelection.choices, blank=False, null=False, default=UKRightoWorkSelection.PASSPORT)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

¿Por qué no pasarlos como variables de contexto?

vistas.py

 from . import models def render_template(request): context = { "options" : models.UK_Right_To_Work.UKRightoWorkSelection } return render(request, "template.html", context=context)

Luego en tu plantilla:

 var enumValue1 = "{{options.PASSPORT}}"; ...
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!