Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 4 months ago by PulsarProbe204

How can I optimize updating Objective background colors from the Color table and manage historical changes?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I have a grid display of boxes where each box’s background color is determined by a value in the Objectives table. The Color table holds the hex colors corresponding to that value, so updating the Color table affects the program globally. I'm using a column sled value instead of just an ID so that I can reference the color easily without tracking row deletions.

I update the Objectives table by looking up the corresponding color in the Color table. Here’s the current approach:

PYTHON
objective_num = Objectives.objects.filter(dashboard=dashboard_id).values('id','objective_color') # get dic of latest color values for each id for n in objective_num: # Iterate over all the objectives color_hex = n.get('objective_color') # get color code to use to get corresponding hex value from Color table obj_id = n.get('id') # get objective id for the color color = Color.objects.filter(value=color_hex).values_list('objective_background', flat=True) # get color hex value that matches the color set in Objectives Objectives.objects.filter(dashboard=dashboard_id).filter(id=obj_id).update(objective_background=color) # update color hex in Objectives table

I have two questions:

  1. While this method works, it feels excessively heavy. Is there a more efficient way to update the Objective background colors when the values change?

  2. Although I only need current values right now, I might want to store historical data in the future. I'm considering two approaches: adding a new column for each update (an Excel-like approach) or inserting new rows with each update and numbering them. Which method is more suitable for tracking historical changes?

Below are simplified versions of my models:

PYTHON
class Color(models.Model): color = models.CharField(max_length=10, default='White') objective_background = models.CharField(max_length=7, default='#FFFFFF') value = models.IntegerField(default=1) def __str__(self): return f"{self.color} (Hex: {self.objective_background}) is color number {self.value} with ID {self.id}" class Objectives(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) dashboard = models.ForeignKey(Dashboard, on_delete=models.CASCADE) objective_background = models.CharField(max_length=8, default=1) row = models.ForeignKey(Row, on_delete=models.CASCADE) objective_position = models.IntegerField() objective_color = models.IntegerField() # Used to store status color based on performance objective_text = models.CharField(max_length=1000, blank=True) timestamp = models.TimeField(auto_now=True) def __str__(self): return f"Objective: {self.row} {self.objective_position} {self.objective_text} at {self.timestamp}"

Any suggestions or improvements would be appreciated.

1

Comments 0

Answers 0

Views 105

0 Answers

Discussion

No comments yet.