I've finally got round to doing a bit of coding in Django to help produce useful applications for the charity that I'm visiting out in India. So far it's been a pretty painfree experience, and I'm learning more and more about django, which is speeding me up no end.
One of the applications that I'm writing at the moment is an online application form for future volunteers. I've written out a model for each of the categories of information that I need to collect, and have created a template and view for displaying that information for end-users. I also have a view for those people that are logged onto the admin interface for viewing each of the volunteer applications.
However, I believe there are a few shortcomings in my design that I want to overcome. The first is that with each separate model I have linked it back to the original CoreInfo model (containing the volunteer's name) using a ForeignKey. I'm not sure this is the best way to do this, so please advise if you can tell me a better way.
full_name = models.CharField(max_length=100)
preferred_name = models.CharField(max_length=100)
dob = models.DateField()
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
email = models.EmailField()
healthy = models.BooleanField()
home_address = models.ForeignKey('Address'related_name='home_addr')
term_address = models.ForeignKey('Address', related_name='term_addr')
flat_number = models.PositiveIntegerField(blank=True,null=True)
flat_name = models.CharField(max_length=100, blank=True, null=True)
number = models.PositiveIntegerField()
road = models.CharField(max_length=100)
town_city = models.CharField(max_length=100)
county = models.CharField(max_length=100)
post_code = models.CharField(max_length=10)
country = models.CharField(max_length=100)
return '%s %s' % (self.number, self.road)
The second problem I have is that in four of the models, I require the end-user to enter in an Address. Rather than having to retype all the address fields twice, I created an Address class and have linked CoreInfo to it by ForeignKey. However, I want the user who is accessing the form to only be able to access Addresses from the drop-down that they themselves have entered. I think I can do this using django sessions, and adding the random session value to the address field, and then filtering the choice list by whether it contains the ID of the session.
The main problem I have is organising this in a forms.py though. I'm using FormWizard to iterate through each of my forms, and in doing so appear to have lost fine-tuned access to displaying the home_address and term_address fields. I'd like to know where to edit their attributes, as I'd want a popup for adding a new address as is done in the admin. Chances are the term_address might match the home_address, so the drop-down box (current view) with the green '+' would be perfect.
Hopefully someone who's django fu is strong will be able to advise me; I wait in joyful anticipation.