Complex models vs simple UIs
An experience report.
I'm hacking out a temporary app for the Madison WI Mutual Aid Network Everywhere Gardens project by forking our ancient valuenetwork software: https://github.com/mikorizal/valuenetwork
The structure for a garden is:
- an EconomicResource of ResourceType "Garden Plot", located at
- a Location, and
- provided by an EconomicAgent
- who is also associated with the Everywhere Gardens project (another EconomicAgent) as a Garden Provider.
[Note: those are the names from our older software. In ValueFlows, ResourceType would be called ResourceSpecification.]
I put together a slide deck showing how you could create such an assembly by creating and connecting all of the components.
That's crazy!
So, before anybody decides to take revenge on me for cruel and unusual punishment, I simplified the process into one form:
Here's the python code that assembled the components from the form:
data = new_garden_form.cleaned_data
garden_name = data['garden_name']
gprt = EconomicResourceType.objects.get(name="Garden plot")
address = data['address']
garden_latitude = data['latitude']
garden_longitude = data['longitude']
qty = data['size_in_sq_ft']
notes = data['description']
loc = Location(
name=garden_name,
address=address,
#Latitude and longitude are hidden fields in the form
#set by the geolocator.
latitude=garden_latitude,
longitude=garden_longitude,
)
loc.save()
garden = EconomicResource(
resource_type=gprt,
identifier=garden_name,
quantity=qty,
notes=notes,
current_location=loc,
)
garden.save()
provider = data['choose_known_provider']
if not provider:
new_provider = data['or_add_new_provider']
at = data['new_provider_type']
provider = EconomicAgent(
name=new_provider,
nick=new_provider,
agent_type=at,
primary_location=loc,
)
provider.save()
if provider:
eg = EconomicAgent.objects.get(name="Everywhere Gardens")
association_type = AgentAssociationType.objects.get(name="Garden Provider")
if not provider.is_associate_of_type_with(eg, association_type):
association = AgentAssociation(
is_associate=provider,
has_associate=eg,
association_type=association_type,
)
association.save()
owner_roles = AgentResourceRoleType.objects.filter(is_owner=True)
if owner_roles:
owner = owner_roles[0]
ownership = AgentResourceRole(
agent=provider,
resource=garden,
role=owner,
is_contact=True,
)
ownership.save()
You can also see by some of the hard-coded selections that this is a hack for this project and not a general-purpose solution for the multitudes and ages.
But this is an example of what a lot of people will need to do with VF models.
I think the complexity of the models is justified and necessary and may write a comment below explaining why, but enough for now to write up this experience.