0

I am using geodjango to create data repository , and have a basic model to store the contents of a shape file . I want to have multiple tables , with attributes generated on the fly . There are tables that deal with user , and one table that deal with each shape file .

What I want to know is , I have a basic model that creates a table per shape file . What I want is also another table that deals with the user . So , should I create another model or another class in the same model ?

Thus , if I want to have multiple tables , should I create multiple models or multiple classes ?

If multiple models , then how do I link it to a view ?

1
  • It sounds as though you are confusing 'models.py' with model classes inside the file. Commented Jan 27, 2015 at 16:35

1 Answer 1

1

A model is merely a programmatic representation of a database table. There's a one-to-one correlation, i.e. for every model you get a database table.

The concept of models is separate from the concept of views. Views are just methods that respond to HTTP requests. In any view you can import and utilize any model; you simply import the model and do whatever you please with it.

It sounds like you're very new to Django and the whole concept of MVC (Model-View-Controller) architecture, in general. You should spend some time reading the Django Book; it's available free online. Focus in particular on the chapters on Models and Views. The Django Documentation is a little more high level but has a wealth of information.

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

3 Comments

We should probably clarify that there's not, strictly speaking, a one-to-one correlation between models and tables. For example, if you have two models, one with a ManyToManyField to the other, you will have a table for each of your models and a linking table: 2 models, 3 tables.
In one sense, yes. In another, there's an implicit Model that correlates to the third table. It's just you don't define it: Django does. Still, I was intentionally being simplistic.
I just thought I ought to mention it for clarity.

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.