Problem viewing data model in select in html edit form

Good evening everyone

I have this case

class Organization(models.Model):
    organization_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=160)
    class Meta:
        db_table = "organization"
    def __str__(self):

class BusinessUnit(models.Model):
    business_unit_id = models.AutoField(primary_key=True)
    organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True)
    name = models.CharField(max_length=160)
    description = models.TextField(null=True, blank=True)
    division_name = models.CharField(max_length=100, null=True, blank=True)
    credit_limit = models.FloatField(null=True, blank=True)
    cost_center = models.CharField(max_length=100, null=True, blank=True)
    web_site_url = models.URLField(max_length=200, null=True, blank=True)
    ftp_site_url = models.URLField(max_length=200, null=True, blank=True)
    email_address = models.EmailField(max_length=100, null=True, blank=True)
    class Meta:
        db_table = "businessunit"
    def __str__(self):

def BusinessUnitEdit(request, business_unit_id):  
    businessunit = BusinessUnitv.objects.get(business_unit_id=business_unit_id)
    queryset = Organizationv.objects.all()
    context= {'Organization': queryset}
    return render(request,'BusinessUnitEdit.html', {'businessunit':businessunit})


    <div class="form-group row"> 
      <label class="col-sm-2 col-form-label">Organization:</label>   
    <div class="col-sm-4">
      {%for itens in businessunit %}
      <option value="{{businessunit.business_unit_id}}" name='{{}}'>{{}}</option>

However, in no way can I view the data in this table name organization

Can anyone help?

Welcome @tiagoceluppi !

Side note: When posting code (or templates, error messages, tracebacks, etc), enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I’ve taken the liberty of editing your original post. Please remember to do this in the future.)

I’m not following what your issue is relative to the template you’re showing here.

Also, it appears you have a number of typos in the code you’ve posted. Please copy/paste the actual code that you’re having issues with. It’s a lot easier to debug things that way without trying to figure out what errors are simply being caused by having tried to retype the code.

Yes, in the model I am putting the select tag, but no matter how I write it, it does not return any record from the organization table, and therefore in the select it does not return any value, I don’t know if my problem is in or in writing the code in python in html.


{% load static %}

<link rel="stylesheet" href="{% static 'css/style.css' %}"/>  
{% csrf_token %}

Update Data

{%for itens in businessunit %} {{}} {%endfor%}
Division Name:
Credit Limit:
Cost Center:
Web Site Url:
Ftp Site Url:
Email Address:

I try to view the result in my view

def BusinessUnitEdit(request, business_unit_id):
businessunit = BusinessUnitv.objects.get(business_unit_id=business_unit_id)
organization = Organizationv.objects.all()
for organization in organization:
return render(request,‘BusinessUnitEdit.html’, {‘businessunit’:businessunit})

Result in log
Empresa 1
Empresa 3
Empresa 3

and change code in BusinessEdit.htm

<div class="col-sm-4">
  <select name="organization" id="id_organization" class="form-control">
    {% for organization in organization %}
      <option value="{{ }}" {% if organization.organization_id == businessunit.organization_id %}selected{% endif %}>{{ }}</option>

But, the fields still don’t appear, does anyone know why?


Foi a contrução da view, mais consegui achar o problema.