N
N
nurzhannogerbek2017-04-27 07:26:01
Django
nurzhannogerbek, 2017-04-27 07:26:01

Why is the button not displayed in the template?

Hello!
There are two data models: Project (Project) and Purpose (Assignment).
models.py:

class Purpose(models.Model):
    code = models.UUIDField(_('Code'), primary_key=True, default=uuid.uuid4, editable=False)
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    text = models.TextField(_('Text'))
    comments = models.ManyToManyField("Comment")

Each project can have only one assignment. I'm trying to show a purpose-add-button on the project_detail page , only if the project doesn't have an assignment. And to be more precise, if there is no Purpose object with the same value in the project field . Why doesn't the below code render the button? views.py:

def project_detail(request, project_code):
       *some code*
       purpose_is_not_exist = Purpose.objects.exclude(project=project_code).exists()
       *some code*

project_detail.html:
{% if purpose_is_not_exist %}
   <button id="purpose-add-button"></button>
{% endif %}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question