Remo
Remo

Reputation: 113

Problem updating the values of a table in django

In the bast_tag.py file I fetch the information from the site settings table which has only one row and then display it in the template. When I want to update the values in this row in the admin panel, the information is not updated, in order for the values to be updated, I have to stop the server and run the command 'py manage.py runserver' again! please guide me. Thank You

base_tag.py:

_site = Settings.objects.first()
@register.simple_tag
def title_site():
    return _site.title


@register.simple_tag
def description_site():
    return _site.description


@register.simple_tag
def five_icon_site():
    return _site.five_icon.url

@register.inclusion_tag("wooden/partials/footer.html")
def footer_tag():
    context = {
        'about': _site.about,
        'logo': _site.logo_ftr.url,
    }
   return context

footer.html:

<div class="d-flex justify-content-around align-items-center flex-column ftr_center wow fadeInUp">
        <img src="{{logo}}">
        <p class="text-center">
            {{about}}
        </p>
      </div>

head tag in index.html:

<title>{% title_site %}</title>
<meta name="description" content="{% description_site %}">

Upvotes: 0

Views: 31

Answers (1)

neverwalkaloner
neverwalkaloner

Reputation: 47374

You should do DB query inside method. Otherwise the query is being executed only once when django is started. Try this:

@register.simple_tag
def title_site():
    _site = Settings.objects.first()
    return _site.title

Same for other tags. You need to run a DB query inside those methods too. If you don't want your query to be executed multiple times you can use a custom context processor.

Upvotes: 1

Related Questions