In order to choose a partner to work with, we simply create a form with a single field, which we can populate with values obtained from the database. In order to accomplish this, we need the following:
- A Django form with a ChoiceField()
- A domain service method that performs the lookup that populates the field
For this purpose, in the property app within our Django website, we define the following form:
class ChoosePartnerForm(forms.Form) :
partSvc = PartnerService(Config())
partKeys = partSvc.fetchPartnerKeys()
alnumPunc = RegexValidator(r'^[\w\.\-\,\"\' ]+$',
'Only letters, numbers, spaces and punctuation are allowed.')
prop_partnerKey = forms.ChoiceField(label='Partner',choices=partKeys)
We also need a method in the partner domain service to retrieve partner names and keys for display, which we call fetchPartnerKeys(). We use the projection argument to the pymongo.collection.find() method to limit...