models.py 875 Bytes
Newer Older
okhin's avatar
okhin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
from django.db import models
from django.utils.translation import ugettext_lazy as _

class Importer(models.Model):
    """Importer model. Used to populate campaign with contacts"""
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=64)
    kind = models.CharField(max_length=4, choices=[('FILE', _("File"))])
    data_format = models.CharField(max_length=4, choices=[('JSON', 'json'), ('CSV', 'csv')])
    file = models.FileField(upload_to='imports/', blank=True, null=True)
    url = models.URLField(blank=True, null=True)
    campaign = models.ForeignKey('Campaign', on_delete=models.SET_NULL)

    def __str__(self):
        return _(u'%{name}: %{format} %{type} importer' % {'format': self.data_format,
                                                'type': self.kind,
                                                'name': self.name})