This looks like exactly what I need. And I wonder if I can through in a few
more methods in the attribute model to make forms, etc, a little easier.
Thanks! And I'll let you know if I actually get it to work!
On 8/24/07, r_f_d <[EMAIL PROTECTED]> wrote:
>
>
> I will not say that it is pretty, but, I looked into doing this a
> while ago for an app I am developing. I wanted to create a system
> that could inventory and track many different types of assets, and
> allow for users to essentially create additional asset types on the
> fly. Essentially, I decided upon using meta-tables to provide the
> flexibility, it passed the smell-test with a couple of database
> architect friends of mine (not my specialty), but was essentially too
> complex to provide enough return for my particular situation. What I
> came up with is something like this (code is abbreviated, and this is
> off the top of my head):
>
> class attributetype(model):
> data_type_choices=(bool, text, char, int)
> name = charfield()
> number_allowed = intfield()
> data_type = charfield(choices=data_type_choices)
>
> class attribute(model):
> type = foreignkey(attributetype)
> booldata = booleanfield()
> textdata = charfield()
> intdata = integerfield()
>
> def __str__(self):
> if type.data_type == text:
> return('%s' % textdata)
> if type.data_type == char:
> etc....
>
> class AssetType(Model):
> name = charfield()
> attribute_types = manytomany(attributetype)
>
> class Asset(Model):
> name = models.charfield()
> type = models.foreignkey(assettype)
> attributes = manytomany(attributes)
>
> Building a form for adding or updating an Asset was obviously not
> trivial. You would have to write a function that would look at the
> asset type, and create formfields for the asset based on what
> attributetypes and the number allowed by the attribute defined. This
> did mean though, that if I had two assets that shared an attribute but
> had conflicting numbers allowed, I needed to create two separate
> attribute types. Using (something like) this I could create any kind
> of asset I wanted to and create the necessary attributes required to
> store pertinent information. Like I said, the complexity outweighed
> what I believed to be the return in my particular case. Hope this
> helps.
> -rfd
>
>
> On Aug 24, 11:29 am, "Nathaniel Martin" <[EMAIL PROTECTED]>
> wrote:
> > Hmmm, that's an interesting method. I was hoping for some way to add
> > attributes though. Does anyone else have any ideas?
> > -Nate
> >
> > On 8/23/07, Thomas Guettler <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > Am Freitag, 24. August 2007 00:50 schrieb Nathaniel Martin:
> > > > I'm hoping that some of the django experts on this list can help me
> with
> > > a
> > > > problem I'm working on designing the architecture of a site I'm
> working
> > > on.
> > > > I want to have many objects that each belong to a category. Each
> > > category
> > > > has a bunch of attributes. Each object would set values for each of
> > > those
> > > > attributes.
> >
> > > ...
> > > [cut]
> > > > B) Have an 'Objects' table, a 'Categories' table, and multiple
> > > 'Attributes'
> > > > tables, one for each datatype I think will be used. The 'Objects'
> table
> > > has
> > > > a column tying it to a certain category. The 'Categories' table has
> a
> > > > column for each attribute table, and lists which attributes are used
> for
> > > > which table. Each 'Attribute' table stores all the attributes of
> that
> > > > datatype, with a column pointing to which category and object it's
> for.
> >
> > > > Downsides: Really complicated. I can see this getting very messy
> very
> > > > quickly. Lots of tables.
> >
> > > I have started an application that uses this approach. It is far from
> > > being
> > > finished. I do something like inheritance at database level:
> >
> > > One Category can have an other Category as parent. A subcategory has
> > > all the attributes of its parent and grandparents.
> >
> > > The user can:
> > > - change the hierarchie of categories
> > > - add categories
> > > - add existing attributes to categories
> >
> > > Up to now he can't:
> > > - add new attributes. (
> > > This would need a python file and something like syncdb.
> > > That should be done by a developer)
> >
> > > Thomas
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---