Electronics & Programming


Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Best model layout for option variance [RSS Feed]

#1 Jan. 10, 2011 11:46:11

Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Best model layout for option variance

I am building an interface that consists of several fields, mostly
drop down boxes (menus). Depending on the menu item (option) selected
in each menu, however, there may be a unique set of "properties" that
the user should be presented with. e.g. "Option A may have the
customizable properties Quantity and Size, Option B may have the
property Radius only, and still Option C may have no properties at
all." and properties may be text input, or perhaps another menu

I am trying to determine the best method of setting this up in
Django. Here are my two ideas:

IDEA #1: Use a class for each set of menu items, a class for each set
of options, and store the possible properties in a dict.

class MenuItem(models.Model):
item = models.CharField(max_length=200, unique=True)

class Option(models.Model):
key = models.CharField(max_length=200)
value = models.CharField(max_length=200)

class Category(models.Model):
selection = models.ForeignKey(MenuItem)
options = models.ManyToManyField(Option, null=True)
'Option A': {
'quantity': {
'type': 'text',
'size': {
'type': 'menu',
'options': ('1 inch', '2 inches', '3 inches'),
'Option B': {
'radius': {
'type': 'text',

class MyForm(models.Model):
category = models.ForeignKey(Category)

This is obviously a generic layout. In reality, there will be
Category, MenuItem, and Option base classes, and copies (inherited)
of all 3 for each category with an specific option rules needed.
Initial data would obviously have to be put in the DB before this
would work at all.

IDEA #2: Put the whole set of categories, options and rules in a
dictionary and scrap the Category, MenuItem, and Option models all
together. I figure performance would be marginally better this way,
and also easier to code/modify (maybe).

Is there another solution I'm missing here? I want to weigh all
options before fully committing. It's a fairly large project and I'd
like to get it right the first time.

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
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.


  • Root
  • » Django
  • » Best model layout for option variance [RSS Feed]

Board footer

Moderator control

Enjoy the 19th of October

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support