Giter Site home page Giter Site logo

Comments (3)

jezdez avatar jezdez commented on May 31, 2024

No, it should not update the cache if your ForeignKey is changed. To quote the docs: "dbtemplates uses Django’s default caching infrastructure for caching, and operates automatically when creating, updating or deleting templates in the database". That applies to changing the templates, but not to setting relations to a template.

As to what you're trying to accomplish, I'm out of ideas. If you're simply changing the relation to a template, and use the template's name field in your get_template_names view method, I don't see how the cache needs to be invalidated at all. Each template has separate names after all, so the template loader will now what to do when it tries to load the template form the database.

from django-dbtemplates.

aschriner avatar aschriner commented on May 31, 2024

Good point about caching and ForeignKey relations. Maybe the issue is not related to caching? As you describe, I am returning the template's '' field in '<get_template_names>'. (I also have a default template as a fallback because the template field is not required).

So here's the sequence I just went though.

  1. No template set on model (ie foreignkey is empty) -> loads default template in browser, no problem
  2. Using admin, update template field on model, set to existing Template object in database ("foo/sometemplate.html"), save model. Still loads default template in browser (not sure why this is - I think this problem is in my code though).
  3. Restart server process
  4. Try to load page, error TemplateDoesNotExist (correctly returns the name of the Template object I chose "foo/sometemplate.html", however).

Debug Template-loader postmortem says:
Django tried loading these templates, in this order:

* Using loader dbtemplates.loader.Loader:
* Using loader django.template.loaders.filesystem.Loader:
* Using loader django.template.loaders.app_directories.Loader: 
    * places
    * places
    * etc
  1. Go to admin page, run "repopulate cache with selected templates"
  2. page loads with correct template from dbtemplates

from django-dbtemplates.

aschriner avatar aschriner commented on May 31, 2024

Further info:

Forgetting about the part with changing foreignkeys on my models...

If I leave the foreign key alone, and have no cache settings in my settings.py, I will get TemplateDoesNotExist when I try to load a page with that template. Then I go to the admin, "Repopulate cache with selected template", and the page loads ok. Wait a few minutes, and then try to load page again. I get TemplateDoesNotExist again.

So without cache settings created in settings.py, I'm not sure where the "Repopulate cache with selected template" is loading the template to. But it seems that the Loader is not correctly falling back to getting the template from the database if it fails to find it in the cache.

Hope that helps pinpoint the issue.

from django-dbtemplates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.