I have Rule
Model which has multiple RuleCondtion
and RuleAction
. I want to export these into a csv file. I am using django import-export
for this.
Example:
name, priority, tags, conditions, actions
Rule 1, 1000, "tag1,tag2", "[{"identifier":"A", "operator":"B"..}]", "[{"identifier":"A", "operator":"B"..}]"
My Models:
class Rule(models.Model):
name = models.CharField(max_length=128, help_text="Name of Rule")
description = models.TextField(help_text="Brief Description of Rule", blank=True)
priority = models.IntegerField(default=1000, help_text="Priority of rule, lesser applies first")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
tags = models.ManyToManyField('Tag', blank=True)
disabled = models.BooleanField(default=True)
def __str__(self):
return self.name
class RuleCondition(models.Model):
identifier = models.CharField(max_length=128, help_text="Select a Property", blank=True)
operator = models.CharField(max_length=128, help_text="Select an Operator", blank=True, choices=CONDITION_OPERATOR_CHOICES)
value = models.TextField(help_text="Content to match the rule")
rule = models.ForeignKey('Rule', on_delete=models.CASCADE, related_name='conditions')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return 'Rule Condition ' + str(self.id)
class RuleAction(models.Model):
identifier = models.CharField(max_length=128, help_text="Select a Property", blank=True)
operator = models.CharField(max_length=128, help_text="Select an Operator", blank=True, choices=ACTION_OPERATOR_CHOICES)
value = models.TextField(help_text="Content to apply on the rule")
rule = models.ForeignKey('Rule', on_delete=models.CASCADE, related_name='actions')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return 'Rule Action ' + str(self.id)
How can I achieve this, there is no option in the django import-export
to do this.