tags:

views:

117

answers:

2

I'm writing a web application to manage a "game". Here are the models:

class Character(db.Model):
    # Bio
    name = db.StringProperty()
    player = db.StringProperty()
    level = db.IntegerProperty()

class Item(db.Model):
    name = db.StringProperty()
    description = db.StringProperty()
    value = db.StringProperty()

class Inventory(db.Model):
    character = db.ReferenceProperty(Character,required=True,collection_name="inventory")
    item = db.ReferenceProperty(Item,required=True,collection_name="inventory")
    quantity = db.IntegerProperty()
equipped = db.BooleanProperty()

I've an Item database, and when I add a character I want to manage its Inventory. I've tried ModelForms but they can't handle this sort of things. My idea is to display the complete Item list, each Item with an associated form quantity,equipped. Something like:

Sword :
  quantity ___
  equipped _
Armor :
  quantity ___
  equipped _

But, how to ship additional informations in forms?

P.S. I'm sorry that the question is dumb and not general, but I couldn't find the keywords to generalize it..

A: 

you will want to look at inline formsets. http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets

Brandon H
+1  A: 

Not sure if I understand you correctly, but if you want to show the Inventory of a Character in a form and place the form of the Character at the same page, you should check out inline formsets the doc

Using inline formsets you can do something like this:

character= get_object_or_404(Character, pk=character_id)
InventoryInlineFormSet = inlineformset_factory(Character, Inventory, max_num=1)
classificationformset = ClassificationInlineFormSet(instance=character)

Out of this form you can manage your items, for example if you have a ManyToMany Relationship to your Items model you can handle them with ajax-filtered-fields link

HTH

Tom Tom