I'm still struggling with obtaining a nice list of items for a samurai in
the admin view. I can iterate over them in a template, but I want to get
them all at once in an admin view without iteration. I have a separate model
for Inventory which has foreign keys for Samurai and Item. The trick is to
Thanks again for the help, and thank you very much for the links! I have
been looking for examples of django rpgs with little success. Once I get
something functional I plan to contribute to the open-source community as
well.
Cheers.
-Tim
On Fri, Feb 19, 2010 at 3:02 PM, Tim Shaffer wrote:
>
You should be able to list all of a samurai's items by doing the
following:
samurai = Samurai.objects.get(pk=1)
for inv in samurai.inventory_set.all():
print inv.item.name
samurai.inventory_set returns a QuerySet the same way that
Inventory.objects returns a QuerySet, but it only returns inve
Hi Tim,
Thanks for the concrete examples. I actually had exactly what you had coded
last night, but I got rid of it because having multiple inventories for a
single samurai seemed counter-intuitive to me. But it sounds like it's the
best way to get the granularity I want.
Going back to that syste
Basically what you are trying to do is called a many-to-many
relationship with an intermediary table.
If it was a regular many-to-many relationship, you could just do
ManyToManyField(Item) on the samurai model, and there would be a table
with a foreign key to item, and a foreign key to samurai, an
Okay, I'm still lacking understanding on the inventory part. Here's what I
have so far:
class Inventory(models.Model):
id = models.AutoField(primary_key=True, verbose_name="inventory")
samurai_id = models.ForeignKey('Samurai')
item_id = models.ManyToManyField(Item)
condition = mode
This has proven very helpful, thank you!
I've decided to implement it like this:
Samurai: Autofield ID (primary, unique)
Item: Autofield ID (primary, unique)
Inventory: Autofield ID, ForeignKey('Samurai'), ForeignKey('Item'),
Condition = IntegerField
This seems to do what I want.
Looking throug
1) You can change this in your model. Check out "verbose_name" and
"verbose_name_plural" for the model's Meta class.
http://docs.djangoproject.com/en/dev/ref/models/options/
2) If you have a ManyToMany field to samurai on the item, you don't
need the inventory model at all. A samurai's inventory
Hello, I'm new to Django, but learning as fast as I can. I would
appreciate some technical help and some database design advice...
**
1) Admin pluralizing question
So I have three models: samurai, item, inventory
When I login to the admin screen it has chosen to pluralize them as:
samurais, item
9 matches
Mail list logo