I'm new to Django and programming overall. So far, I was able to build a website just by referring to the official docs, but now I'm stuck. I'll describe my problem using gas stations analogy.
This is what I got:
class Grade(models.Model):
grade_name = models.CharField(max_length=30)
class Station(models.Model):
station_name = models.CharField(max_length=30)
gas_grade = models.ManyToManyField(Grade)
With that I create three grade objects: Regular, Plus, Premium. After that I create a few stations to which I "assign" any combination of grades. Easy.
The problem starts when I need prices. An obvious solution would be adding Price model:
class Price(models.Model):
station = models.ForeignKey(Station, on_delete=models.CASCADE)
price_regular = models.CharField(max_length=30)
price_plus = models.CharField(max_length=30)
price_premium = models.CharField(max_length=30)
But adding the last three fields manually is no fun, to say the least. My "grades" and "stations" can grow daily. They also have two fields representing min/max price.
So... can I dynamically create fields based on existing objects? The point is I need each new station to have a price field for each grade assigned.
Please advise of any of my options.
It's almost a week since I'm beating the dead horse. Maybe I'm far from figuring this out because the logic I'm following is wrong?
Maybe a dedicated "add station" form outside of Django admin could work? But I assume that would require some good amount of javascript involved.
Thank you.