0

I have a Django model that represents data files on a server, with some metadata about each file. These files are generated by an instrument and can appear at any time throughout the day. I would like the Django table to reflect the files that are actually available for the user to select.

Here is what I have so far:

  • I have a python script that scans the directory, produces an intial_data.json file and puts it in the app/fixtures directory. (The script pulls out important metadata from each file to make it easy for the user to make selections.)
  • I have fixtures working so that when I run syncdb, it loads the data into the model.

My question is, how do I do this repeatedly (hourly? on-demand? -- for example, triggered by clicking a button on the page?)

My impression is that syncdb is only meant to be run occasionally, like, for a data migration. Am I wrong - can I run it "at the click of a button"?

Is there a better way of keeping my table in sync with the file system? I have considered using FileField or FilePathField but these seem not workable, because I want to pre-load the table with the file metadata.

3
  • 1
    I don't see anything horrible about the idea you've described, but why not turn the Python script that scans the directory into one that writes directly to the DB? If you don't want to do that, you could simplify down to using the loaddata command instead of syncdb: docs.djangoproject.com/en/dev/ref/django-admin/… Commented Nov 22, 2013 at 1:27
  • 1
    syncdb is definitely intended to be something only run in setup, and not to be something you run as part of your app's normal operation. If it's only fixtures you need, though, then fortunately you have a lot of options on how to load those aside from syncdb. Commented Nov 22, 2013 at 8:48
  • Thank you both for the helpful comments. I'm accepting the below answer for the sake of closing the question. Commented Nov 22, 2013 at 17:09

1 Answer 1

1

I don't understand why you want you use syncdb for this. That's really for creating tables. If all you're doing is loading a fixture, why don't you do that directly? You can use django.core.serializers to parse and load your JSON file (and I'd recommend calling it something other than initial_data).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.