0

As the question states, I want to create multiple models of same type. Let's say I've got this simple class for sensor data:

class Sensor_data(models.Model):
    value = models.FloatField()
    #other stuff

And all sensors in my system have a unique ID.
So I would be able to create an own data-table for these sensor by naming them SensorID.Sensor_data ( I want to do this because each sensor will generate a large amount of data )

I've read about dynamic models, but since I don't need to be able to register new sensor in runtime, I've not tried to implement it. (Or is this the best way??)

And even if I manage to create multiple models of same type, how can I register all those models to admin site and manage them as super-admin? (Thinking of that the django admin only can register one type per object? right? ) thinking of the model is already registered Error <-------- Not sure about this

So what would you do? To e.g. create 100 tables of same type?

Keep in mind that I'm kind of new to both django and python

Pär Eriksson
  • 367
  • 2
  • 9
  • Why not create `type` column in your table that would describe the sensor type? – matino Jun 28 '13 at 09:05
  • 3
    Pleas see http://stackoverflow.com/a/16768830/671575 – Seppo Erviälä Jun 28 '13 at 09:30
  • @SeppoErviälä, so you think partitioning is the way to go? What is the best way to structure the partitioning in this case? Let's say that I get new values each 10 seconds for each sensor in my system. Should I then: Partitioning by different date-stamps, let's say each week so the table storing the data won't get too large. And still have the relationship with Sensor by sensor_id ? **or** Partitioning by the sensor_id so each data-table is connected to each sensor? (sounds to me like the best option here though) – Pär Eriksson Jun 29 '13 at 08:48
  • @SeppoErviälä **And lastly**, do you know any examples of how to implement this in django? – Pär Eriksson Jun 29 '13 at 08:56
  • @matino in my case I will store large amount of data, and I figure that if I use a relation with a sensor the queries will (at some point) be inefficient. If this was what you meant? – Pär Eriksson Jun 29 '13 at 09:07
  • @user2530984 (DISCLAIMER I have not used MySQL partitioning) It depends on your use case. If you regularly need the newest data then you should partition by date and if you regularly need the whole data on a sensor you should partition by sensor_id. – Seppo Erviälä Jun 29 '13 at 13:51
  • @user2530984 Partitioning affects how data is stored in MySQL and should be of no concern to Django. You can partition MySQL db with MySQL tools and still use it with Django application. – Seppo Erviälä Jun 29 '13 at 13:52
  • @SeppoErviälä Okey I will check that out before posting it as an answer. Thanks! – Pär Eriksson Jun 30 '13 at 19:57

0 Answers0