Author Picture

Kim Majali


Admin Stacked Inline and Tabular Inline

Author Avatar wrote on 07/06/2022

Both allow you to edit models on the same page as a parent model.

In other words, it is sometimes preferable for a user to have the possibility to edit a certain model while editing another one instead of having to manually add another instance somewhere else in your interface.

The difference is Layout

Read more

Django URL Path

Author Avatar wrote on 07/06/2022

If a word in path Path


{% if 'account' in request.path %}
    hello world!
{% endif %}
Read more

Built-in Template Tags

Author Avatar wrote on 07/06/2022

Escape

{% autoescape on %}
    {{ body }}
{% endautoescape %}
Read more

Authentication in Template

Author Avatar wrote on 07/06/2022

If user type


        {% if user.profile.user_type == 'SU' or user.profile.user_type == 'AD' %}
        
        {% endif %}
  

If owner


        {% if profile.user == request.user %}
    
        {% endif %}
    
Read more

Declare Variables on Django Templates

Author Avatar wrote on 07/06/2022

Django

Using with

{% with name="Kim" %}
    
Hello {{name}}!
{% endwith %}
With and =

{% with total=business.employees.count %}
    {{ total }} employee{{ total|pluralize }}
{% endwith %}
With and as

{% with business.employees.count as total %}
    {{ total }} employee{{ total|pluralize }}
{% endwith %}
Update variale with JS only

Django & JS

from django to JS
Or

{{ variable|json_script:'name' }}
var js_variable = JSON.parse(document.getElementById('name').textContent);
From input to
Read more

Topics: AdminTemplates