On 14-8-2012 6:58, Jeff Dickens wrote:

> class Md_model(models.Model):
>     Timestamp = 
> models.DateTimeField(auto_now_add=True,unique=True,db_index=True)
>     def __unicode__(self):
>         return self.Timestamp.strftime('%Y %m %d %H:%M')
>     def as_dict(self):
>         return(model_to_dict(self))
>     class Meta:
>         abstract = True
> 
> class md_10_1(Md_model):
>     name='md_10_1'
>     dataSource = 'http://192.168.0.10/auto/001'
>     n1 = models.DecimalField(max_digits=10,decimal_places=3)
>     n2 = models.DecimalField(max_digits=10,decimal_places=3)
>     n3 = models.DecimalField(max_digits=10,decimal_places=3)
> 
> class md_10_2(Md_model):
>     name='md_10_2'
>     dataSource = 'http://192.168.0.10/auto/002'
>     n4 = models.DecimalField(max_digits=10,decimal_places=3)
>     n5 = models.DecimalField(max_digits=10,decimal_places=3)

I'm wondering if this design isn't better:
class DataBatch(models.Model) :
        name = models.CharField(max_length=10)
        url = models.URLField(max_length=200)
        time_stamp = models.DateTimeField(auto_now_add=True, db_index=True)

class DataType(models.Model) :
        """Different data types, n1 through n5 in your example"""
        name = models.CharField(max_length=10)

class CollectedData(models.Model) :
        batch = models.ForeignKey(DataBatch, related_name='data')
        data_type = models.ForeignKey(DataType)
        data = models.DecimalField(max_digits=10,decimal_places=3)


> Using a foreign key does't make sense to me since I can't predict that any 
> particular model will be in every query.

If you need your own design, then you can actually set a foreign key to
NULL and use hasattr(Md_model, related_name) to test if the foreign key
is available.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to