Hi Loren,
  Think about how you will be querying and presenting / reporting on
the information, that will help you structure your data.  If you be
frequently displaying a large report listing or querying all plant
names and their UOM + pricing information, you might want to
denormalize the data (ie store the name on both the Plant and
PlantItems models).  If you do not need to query the PlantItem data,
you could serialize it and store it in a text-property on the Plant
model.

  If you use a normalized schema, the main thing is to avoid serial
fetches or queries inside a loop, so make sure if you're using a
ReferenceProperty that you do not do something like:

    for item in plant_items:
       name = item.plant.common_name

  Instead do something like this:

    class PlantItem(db.Model):
       plant = db.ReferenceProperty()
       @property
       def plant_key(self):
           return PlantItem.plant.get_value_for_datastore(self)

    plant_keys = list(set([item.plant_key for item in plant_items]))
    plants = dict(zip(plant_keys, db.get(plant_keys)))

    for item in plant_items:
       name = plants[item.plant_key].common_name


  Use Appstats!  It will help you spot problem areas in your code very quickly!



Robert






On Mon, Jan 31, 2011 at 17:34, Loren <[email protected]> wrote:
> Hello,
>
> I'm transitioning an existing PHP + MySql web application over to
> python GAE. It's essentially an inventory management application for a
> plant nursery. The relevant mysql tables are basically:
>
> Plant:
> plant_id                int(8) PRIMARY KEY autoincrement unsigned
> sci_name                varchar(60)
> variety         varchar(60)
> common_name     varchar(60)
> ....
> description             text
> last_modified   timestamp ON_UPDATE_CURRENT_TIMESTAMP
>
>
> PlantItems:
> item_id         int(8) PRIMARY KEY autoincrement UNSINGED
> plant_id                int(8) FOREIGN KEY
> size                    varchar(10) // something like 1_gallon, 2_gallon, etc
> retail_price            decimal(5,2)
> wholesale_price decimal(5,2)
> quantity                int(5)
> last_modified   timestamp ON_UPDATE_CURRENT_TIMESTAMP
>
>
> So the main issue is that each plant, which has lots of info, has
> multiple sizes. There's flats, quart-sized containers, gallon
> containers, etc etc. All the plant-related details are the same
> between them, but they each have a unique quantity and price. In a
> RDMS, I can JOIN on these tables and match up plant_id. I'm trying to
> think of something for the DataStore model that will minimized
> duplicated code.
>
> I know you can store Lists in a db.Model derived class, but not a list
> of tuples. I also though about doing dynamic properties ala
> db.Expando, but that didn't seem to gain much.. Thoughts?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" 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/google-appengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" 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/google-appengine?hl=en.

Reply via email to