I need to store customer loyalty cards.
It should be flexible. I have several variants of cards with different discount systems.
For example, the card by amount of purchases – > $100 – 5%, > $1000 – 10%, etc. Or by amount of visits – > 10 – 3%, 100 – 10%, etc.
Furthermore, it should store the different image for different types of cards and sales amount, for example 5% – silver colour, 10% – gold, etc.
I came up with the idea of storing in in database as JSON.
Visits for example:
schema = {1: {'discount': 5%, image: '....', 'style': {'background': ..., 'foreground': ...},
2: {'discount': 10%, image: '....', 'style': {'background': ..., 'foreground': ...},
3: {'discount': 15%, image: '....', 'style': {'background': ..., 'foreground': ...},
}
class ABSCard(models.Model):
title = field
work_place = field
....
class Discount(models.Model):
type = ....
schema = JSONField
abscard_id = ABSCard
But I’m not sure that storing JSON in PostgreSQL is the best way.