I'm trying to build a ticket system to cover multiple forms for multiple departments. Each ticket form has standard fields for title, date, description. The ticket may need additional fields depending on which department the form is for, i.e marketing might need a where did you hear about us box but accounts will not.
So I have a table that maps field definitions to forms i.e (1) - Where did you hear TextArea ----> (45) Marketing Form
My hope is that based on the form they are selecting, I can show the additional fields relating to the selected form. It didn't generate this by itself when using ModelForm's so I think I'm going to have to do this myself on top.
My first idea is to get all form field objects relating to the particular form (filter(formid=marketing_form)), create fields for them then override the save function to save these form field values before saving the whole form.
I'm new to Django so not sure if there's a better way?
#list of all possible fields for mapping
class Field(models.Model):
field_id = models.IntegerField(primary_key=True)
field_cat = models.ManyToManyField(Category)
field_label = models.CharField(max_length=50)
field_type = models.IntegerField(choices=FIELD_TYPE_CHOICES)
field_enabled = models.BooleanField(default=1)
def __unicode__(self):
return self.field_label
#list of all fields additional fields on a ticket
class TicketField(models.Model):
tf_id = models.IntegerField(primary_key=True)
tf_ticket = models.ForeignKey(Ticket)
tf_field = models.ForeignKey(Field)
tf_0 = models.CharField(max_length=255, blank=True)
tf_1 = models.TextField(blank=True)
tf_2 = models.BooleanField(blank=True)
tf_3 = models.ForeignKey(Employees, blank=True)