I have extended my user mode with a profile that has an optional field that is an array. Each element in the array can be is a unique value from a field in another table. In that specific table, I have a field that is an array field that I want to hold the email addresses of the users that have that option in their array field. Is there a way that I can make it to where that field contains the email addresses of the users that have that particular fields value in their array field? And if that element gets removed from the user profile array field it gets removed from that table’s array as well?
class LocationCodes(models.Model):
location = models.CharField(db_column='location', primary_key=True, max_length=10)# Abbreviated location code
customergroup = ArrayField(models.CharField(db_column='customergroup', max_length=6))
emails = ArrayField(models.CharField(db_column='emails', max_length=60)) #Array field that I want to link to User Model emails
location_name = models.CharField(db_column='location_name', max_length=60)
state = models.CharField(db_column='state', max_length=20)
class UserProfileExtension(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
locations = MultiSelectField(choices=location_code_choices) #This field contains an array of the locations that are from the location field in the LocationCodes table.
I'm basically wanting to link the email address in the user table to the emails field in the LocationCodes table if that user has that particular location in their locations array field.