views:

37

answers:

1

I am just starting out with Django and would like to know the best way to deal with the following data. I have DataSets which are comprised of many x,y coordinate pairs which I wish to plot. It is my understanding that Django doesn't support numeric arrays directly in it's models so what is the best way to deal with these? Right now all I can think of is something like I have below:

class DataSet(models.Model):
    set_name = models.CharField(max_length=100)

class DataPoint(models.Model):
    x = models.FloatField()
    y = models.FloatField()
    dataset = models.ForeignKey(DataSet)

This seems a bit odd and without having any experience with databases or django I am not sure how to proceed. I am using postgresql right now which I believe does support array entries but I am not sure if I am prepared to make a custom field in Django.

+1  A: 

Short of a custom field your idea of defining DataPoint and DataSet models seems to be the way to go. You should consider changing the relationship between the two to a many to many field if there is the possibility of a data point occurring in more than one data set.

It would also help to write (with tests) a thin business layer combining the two to minimize the need to think in terms of how the models are stored in the database.

Manoj Govindan