def equipment_instance_detail(request, *args, **kwargs):
pk = kwargs.get('pk')
equipment_instance = get_object_or_404(EquipmentInstance, pk=pk)
dataset = OpeningData.objects.all().order_by('date').values('date', 'equipment_temperature')
categories = list()
temperature_series = list()
for entry in dataset:
categories.append('%s' % entry['date'])
temperature_series.append(entry['equipment_temperature'])
context = {'categories': json.dumps(categories),
'temperature': json.dumps(temperature_series),
'equipment_instance': equipment_instance}
return render(request, 'webapp/equipment_instance_detail.html', context=context)
So this is a views.py function for a django app that takes in an equipment instance and renders a graph for it. The code above is a function that is configured to make a time series plot using chart.js for a piece of equipment (heat press). The problem is depending on what type of equipment instance it is, the code and visuals could be different.
For example, right now, I have two types of equipment: Heat Press and Microscope. Each piece of equipment has instances of itself which can have data associated with it.
A heat press may only use a time series chart while a microscope could use a histogram and a scatter plot. The difference between the two types of equipment instances will require unique code and probably unique templates. While there are only two equipment instances now, there could be hundreds in the future.
I want something that can handle the massive differences. I could use a gigantic if statement that asks if the equipment instance belongs to a certain type, but that seems janky and not good programming. Is there a better way?
When the user is creating equipment and equipment instances in their system via the admin site they also should create a new equipment data model in models.py.
How do I link the admin site to a function that creates new data classes in models.py?
After days of research, it is beginning to appear that this functionality is not possible. Is there really no way to automatically create a unique django model? Every piece of equipment potentially has different time series data and it would be better to store it in their own models. I believe that the only solution here is to make an extremely fat django model that covers ALL equipment time series data and that new data columns will need to be added manually whenever a piece of new equipment is entered into the django app.