[PYTHON] Make the model a string on a Django HTML template

I had been worried about it for a long time, and I was trying to compare the people who handed it over to the template in the dictionary type, but it didn't work. I finally solved it.

The solution was solved by converting it to a string type and comparing it.

schedule.html


<tbody>
    {% for staff in user_list %}
        <tr align="center">
        <th class="staff_name" staff_id="{{ staff.staff_id }}" width="200" >{{ staff.last_name }} {{ staff.first_name }}</th>  <!--staff_id element used in js-->
        {% for item in object_list %} 
            {% if item.user|stringformat:"s" == staff.username|stringformat:"s" %} ###Convert to string here
                    <td class="day_{{ item.date }}" id="s{{ staff.id }}d{{ item.date }}">
                    {{ item.shift_name_1 }}
                    </td>
                {% endif %}            
        {% endfor %}
        </tr>
    {% endfor %}
</tbody>

Finally. I really had a hard time ... Even if I displayed it on the screen, it was displayed as atsushi, so I didn't understand it for a long time.

I doubt that it can be really compared, and if I compare it with item.user = "atsushi", it is judged that they do not match ... I found out that I didn't recognize it as a string here. It takes a few hours to get here ... (laughs)

Finally I was able to display the registered shifts!

image.png

This is the html that can display this.

schedule/month.py


{% extends 'schedule/base.html' %}
{% block header %}
{% endblock header %}

{% block content %}
<table class="table table-striped table-bordered">
<thead>
    <tr align="center" class="info">    <!--date-->
        <th rowspan="2"></th>
        {% for item in calender_object %}
                <th class="day_{{ item.date }}">{{ item.date | date:"d" }}</th>
        {% endfor %}
    <tr align="center" class="info">   <!--Day of the week-->
        {% for item in youbi_object %}
            <th class="day_{{ item.date }}">{{ item }}</th>
        {% endfor %}
    </tr>
</thead>
<tbody>
    {% for staff in user_list %}
        <tr align="center">
        <th class="staff_name" staff_id="{{ staff.staff_id }}" width="200" >{{ staff.last_name }} {{ staff.first_name }}</th>  <!--staff_id element used in js-->
        {% for item in object_list %} 
                {% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}
                <td class="day_{{ item.date }}" id="s{{ staff.id }}d{{ item.date }}">
                    {% if item.shift_name_1 != None %}
                        {{ item.shift_name_1 }}           
                    {% endif %}
                    {% if item.shift_name_2 != None %}
                        {{ item.shift_name_2 }}               
                    {% endif %}
                    {% if item.shift_name_3 != None %}
                        {{ item.shift_name_3 }}               
                    {% endif %}
                    {% if item.shift_name_4 != None %}
                        {{ item.shift_name_4 }}
                    {% endif %}               
                </td>
            {% endif %}            
        {% endfor %}
        </tr>
    {% endfor %}
</tbody>

</table>
{% endblock content %}

Next, I would like to add a process of coloring depending on the facility.

Finally willing to be happy: relaxed:

Recommended Posts

Make the model a string on a Django HTML template
Make a filter with a django template
Django HTML Template # 2
Django HTML template
Specify the volume on linux and make a sound
Make a breakpoint on the c layer with python
DJango Note: From the beginning (creating a view from a template)
[Django] Make a pull-down menu
The story of a Django model field disappearing from a class
I made a VGG16 model using TensorFlow (on the way)
Django: Import a class from a string
Loop the For statement in reverse in an HTML file on Django
Implement a Django app on Hy
Try Ajax on the Django page
Make a model iterator with PySide
Get the query string (query string) in Django
[Personal memo] Get data on the Web and make it a DataFrame
How to make only one data register on the Django admin screen
DJango Memo: From the beginning (model settings)
Create a model for your Django schedule
Make Jupyter Notebook a service on CentOS
Deploy the Django app on Heroku [Part 2]
Make the SIR model calculation program GUI
Deploy the Django app on Heroku [Part 1]
Make Unity Accelerator a service on Linux
Get a reference model using Django Serializer
A note on enabling PostgreSQL with Django
[Python] A progress bar on the terminal
Implement a Custom User Model in Django
Write a short if-else for Django Template
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
If you want to display values using choices in a template in a Django model
How to count the number of elements in Django and output to a template
Define a division value in Django and easily reflect it on the screen
Let's display a simple template that is ideal for Django for the first time
A model that identifies the guitar with fast.ai
Make a bot for Skype on EC2 (CentOS)
Build a Django environment on Raspberry Pi (MySQL)
A note on customizing the dict list class
DJango Memo: From the beginning (creating a view)
Make a copy of the list in Python
Let's simulate the Izhikevich neuron model on the web!
Calculate the probability of outliers on a boxplot
Specify the view URL in your Django template
Run a Python file from html using Django
Make any key the primary key in Django's model
Decrypt a string encrypted on iOS with Python
Customize the model page on Django's admin screen
Create a GUI on the terminal using curses
I did a little research on the class
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
[Django] No changes detected even if make migrations is executed after creating a Model
The world changed when I opened a big Python project (Django) on Sourcetrail (Linux)
[Django] Hit a command you made from within the process that runs on manage.py.