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

186
Views
filtro de python ninguno de los valores

Tengo:

1. modelos.py

 class Post(models.Model): ROOT_CHOICES = ( ('Manufacturing', 'Manufacturing'), ('Transportation', 'Transportation'), ('Installation', 'Installation'), ('Operation', 'Operation'), ) root1 = models.CharField(max_length=250, choices=ROOT_CHOICES, default='Manufacturing') root2 = models.CharField(max_length=250, choices=ROOT_CHOICES, null=True, blank=True) root3 = models.CharField(max_length=250, choices=ROOT_CHOICES, null=True, blank=True) root4 = models.CharField(max_length=250, choices=ROOT_CHOICES, null=True, blank=True)

2. vistas.py

 def post_detail(request, slug): post=get_object_or_404(Post, slug=slug) if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post=post comment.save() return redirect('data:post_detail', slug=post.slug) else: form=CommentForm() template = 'data/post_detail.html' context = {'form':form,'post':post} return render(request, template, context)

3. html

 <div class="col-sm-3"> <div class="post-parameters"> <p class="text-parameters"> Root: {{ post.root1 }}, {{ post.root2 }}, {{ post.root3 }}, {{ post.root4 }}</p> </div> </div>

Se ve así, en este momento, en mi archivo html: Raíz: Fabricación, Ninguno, Ninguno, Ninguno, que es correcto. Sin embargo, me gustaría no mostrar los valores Ninguno, si los hay, por ejemplo, Raíz: Fabricación

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar el filtro default_if_none , entonces: {{post.root1|default_if_none:""}}

Alternativamente, puede verificar cada valor específicamente

 {% if post.root1 %} {{post.root1}} {% endif %}
over 4 years ago · Santiago Trujillo 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!