How can I save a single value in Django?

My Django app receives an RSS feed every day. I would like to save the time when the feed was updated somewhere in the application. I get only one channel, it will never grow to be multiple channels. How can I save the last updated time?

My ideas are still

  • Create a model and add a datetime field to it. This seems redundant as it adds another table to the database, which will only have one row. In addition, this is the most obvious and straightforward decision.

  • Create a settings object that simply stores key / value mappings. The last updated date will be just a row in this database. This is, in fact, a general version of the previous solution.

  • Use dbsettings / the django-values , which allows you to save settings in the database. The last updated date will be just a "setting".

Any other ideas that I am missing?

+5
source share
7 answers

Although databases regularly store many rows in any table, having a table with only one row is not particularly expensive unless you have (m) any indexes that are wasting space. In fact, most databases create many single-row tables to implement certain functions, such as the monotone sequences used to generate primary keys. I recommend that you create a regular model for this.

+6
  • RAM , : memcached , .
  • XML, .
  • RDMS .
  • Django , CACHE_BACKEND - , ://...

- " ".

settings.py:

 RSS_FETCH_DATETIME_PATH=os.path.join(
     os.path.abspath(os.path.dirname(__file__)),
     'rss_fetch_datetime'
 )

rss- script:

 from django.conf import settings
 handler = open(RSS_FETCH_DATETIME_PATH, 'w+')
 handler.write(int(time.time()))
 handler.close()

:

 from django.conf import settings
 handler = open(RSS_FETCH_DATETIME_PATH, 'r+')
 timestamp = int(handler.read())
 handler.close()

cron - , " ", , 5 :

 0 5 * * * /path/to/manage.py runscript /path/to/retreive/script

, retreive script - , .

, :

1000 .

+2

, , Django. True ( .) , , .

: Flickr Django

+1

, memcached?

, (, ..), - Django , , "" .

0

, - PHP, , xml -, , . , .

0

... ? , siteconfig , . , , JSON, ConfigParser, pickle . import siteconfig -, . , dict (, , 2-3 , , , URL- .)

0

Create a session key that is retained forever and updates the feed timestamp every time you access it.

0
source

All Articles