1

I went through the Django tutorial with in mind to go through it again using it to set up my small app.

So now I am making a simple app where users can search a large set of strings and get a subset as a result. The only relevant search criteria is the first and last character of the string.

So the table is static, meaning I'll fully populate it before app deployment and it will be read only, since the data set doesn't change ever.

A record will consist of a field containing the actual string, a field containing the first character and a field containing the last character, a field containing a json representation of the record (I believe postgres has funcitons to generate that for me) and some fields containing metadata concerning the string. The index will be a composite of the first and last character of the string.

In any case, I research and do as I go, so I need guidance as to the correct approach (as this is use case will be very common for me).

I can either research creating this exact table in postgres an then use a django facility to generate the model from the table (https://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb).

Or I can research how to get Django to create this exact table and write the model accordingly and have Django create the table for me. Bear in mind that I will in either case need to hit the table directly to pre-populate it (or so I believe, please let me know if there is a Django way to do that?).

I would think the former more natural but the docs seem to imply that it's for 'legacy' databases.

What do you recommend as the appropriate approach to start from scratch with.

  • Why are you reimplementing a database on top of an existing database? – whatsisname Aug 17 '15 at 22:41
  • not sure what youre asking. I need the Django ORM to interface with the Database from within the app. thus I will need a model class to represent my table. the standard ORM workflow is to define the model class and let Django create the table according to the class definition. The contrary approach is to create a table directly and use a Django tool that will generate a model class according to the newly created table. I haven't implemented anything yet. Wondering what approach I should be taking in my use case? – naftalimich Aug 17 '15 at 22:57
  • If you are making a simple app from scratch, define your models and have django deal with it for you. That's one of the primary reasons to be using django in the first place. – whatsisname Aug 17 '15 at 23:00
  • ok fair enough, I'm not sure though if Django can create the json field to represent the row as that is postgres function, just don't know. I figured that maybe Django is there for where you neither know nor care about the sql structure of the data, where all you care about is your app level representation, but in an case where you know exactly what you want as you db table structure maybe you would simply not use the table generation functionality, but yeah what you are saying is an answer to my question, and thank you for it. – naftalimich Aug 17 '15 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.