Hi everyone,

I am still having issues with my data models.  I can't tell if the
underlying problem is my model definitions or my inability to do the
queries to manipulate my models to get the output that I want.

Could someone please tell me if this is the right way to do it in my
models.py?

Again, what I want is:

sample1
     disease = asthma
     gender = male
     race = white
sample2
     disease = diabetes
     gender = female
     race = black
sample3
     disease = asthma
     race = white
     cell = lung
sample4
     disease = breast cancer
     gender = female
     race = hispanic

So, each sample is described by one or more facets (i.e., tags) like
disease, race, cell, gender, etc.  Each facet (tag) will have one
value at any one time.
So do I have the following relations?
sample has a many to many relationship with facets.
facets have a 1 to many relationship with values.

I'm kind of unsure if Sample should have just a Facet field,  and then
Facet should have a Value field; or if Sample should have a Facet
field and also a Value field, both in a many to many relationship with
Sample.

Finally, here is my code:

from django.db import models

class Value(models.Model):
        name = models.CharField(max_length=60)
        def __unicode__(self):
                return self.name

class Facet(models.Model):
        name = models.CharField(max_length=60)
        value = models.ForeignKey(Value)

        def __unicode__(self):
                return self.name

class Sample(models.Model):
        number = models.CharField(max_length=30)
        facets = models.ManyToManyField(Facet)
        description = models.TextField()

        def __unicode__(self):
                return u'%s' %(self.number,)

        class Meta:
                ordering = ['number']


Thanks so much!

On Mar 28, 7:52 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Mar 28, 2:28 am, Daniel <unagimiy...@gmail.com> wrote:
>
>
>
> > Hi all,
>
> > I'd appreciate it if you could help me out with something.
>
> > I am trying to build a way to use faceted browsing through a database
> > of biological samples.
>
> > what I want to model is this:
>
> > Sample 1
> >      race = white
> >      age = adult
> >      gene = XCFR2
> >      disease = cancer
> > Sample 2
> >      race = white
> >      age = child
> >      gene = 343GS
> >      disease = stroke
> >      date = 2010
> >      country = Netherlands
>
> > So each sample could contain many tags.  And each tag should have one
> > value at a time.  A tag is a category (like race, age, gene, disease),
> > and a value is for lack of a better word, the choice or free text that
> > is entered to the right of the ='s sign.  TAG = race, then value =
> > white
>
> > So  does each sample have a many to many relationship with tags?  And
> > then tags have a many to many relationship with values?
>
> > Each sample can have many tags (race, age, gene, disease, ...etc).
> > Each tag can have many diff values (race could be white, black,
> > hispanic, asian, etc...) BUT only one at a time
> > Each value should be mapped to one tag at a time.  But I guess a value
> > could be reused, like the value XCFR2 could be a valid in gene = XCFR2
> > and discovered_information = XCFR2.
>
> > I think I'm making it too hard, but if someone can help, I would be
> > happy
>
> Perhaps you want some kind of machinetags implementation? In other
> words, tag a sample with things like "race:white, gene:XCFR2" and so
> on.
>
> I've not used it, but there is a branch of django-tagging that
> supports machinetags 
> here:https://code.launchpad.net/~gregor-muellegger/django-tagging/machinet...
> --
> DR.

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

Reply via email to