Hello all, I'm attempting to create an RPG character generator using
Django. My models are as follows:
from django.db import models
class Character(models.Model):
name = models.CharField(null=False, blank=False, max_length=60)
age = models.IntegerField()
height = models.CharField(null=False, blank=True, max_length=6)
weight = models.CharField(null=False, blank=True, max_length=6)
properties = models.ManyToManyField("Definition")
classes = models.ManyToManyField("CharacterClass")
skills = models.ManyToManyField("CharacterSkill")
attributes = models.ManyToManyField("CharacterAttribute")
inventory = models.ManyToManyField('inv.Item')
def __unicode__(self, ):
return self.name
class DefinitionCategory(models.Model):
label = models.CharField(null=False, blank=False, max_length=15)
def __unicode__(self, ):
return self.label
class Definition(models.Model):
category = models.ForeignKey(DefinitionCategory)
label = models.CharField(null=False, blank=False, max_length=60)
description = models.TextField(null=False, blank=True)
extra = models.TextField(null=False, blank=True)
def __unicode__(self, ):
return "%s -> %s" % (self.category.label, self.label)
class CharacterClass(models.Model):
aClass = models.ForeignKey("Definition")
level = models.IntegerField()
def __unicode__(self, ):
return self.aClass.label
class CharacterSkill(models.Model):
aSkill = models.ForeignKey("Definition")
rank = models.IntegerField()
def __unicode__(self, ):
return self.aSkill.label
class CharacterAttribute(models.Model):
anAttribute = models.ForeignKey("Definition")
score = models.IntegerField()
def __unicode__(self, ):
return self.anAttribute.label
The Definition/DefinitionCategory models allow me to dynamically create
attributes for the character like this:
DefinitionCategory (label)
Label: Race
Definition
Category: Race
Label: Human
Then I link back to the attribute Definition from the Class, Skill and
Attribute models so I can track their level/score etc. The result is
hopefully something like this:
Character -- (Character.name) --> Bob
Character Feats -- (Definition.label (Where category.label is Feat)) -->
Heavy Armor
Character Skills -- (Definition label (Where category.label is Skill)) -->
Tumble -- (CharacterSkill.rank) -- > 4
Character Class -- (Definition label (Where category.label is Class)) -->
Fighter -- (CharacterClass.level) --> 1
The idea is to create a system that allows me to define rules/properties
for different game types. So you could have a Pathfinder character
generator and use the same system to create a DnD character generator etc
instead of hardcoding the attributes etc into the character model.
At the moment the Django admin interface sort of works for this, it allows
me to assign different feats/skills etc but it requires an extra step. What
I'm having trouble coming up with is a way to have a form like this: (< >
represent fields)
<Character Name (Text field)>
<Race (Select box - Definition.objects.filter(category__label='Race'))>
<Race (Select box - Definition.objects.filter(category__label='Class'))><
Class Level (Text field)>
<Race (Select box -
Definition.objects.filter(category__label='Skill'))><Skill Rank (Text
field)>
<Race (Select box -
Definition.objects.filter(category__label=Attribute'))>< Attribute score
(Text field)>
I was on my way to creating a fully custom form in templates but that
doesn't seem very django-y. I also discovered the queryset component in
Select fields. I feel like there should be a way to do this and it may be
simple but I've thought myself into a tangled mess. Any help would be
appreciated. Thanks!
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.