URL for FileField

223 views Asked by At

What is the most simple solution to such a problem: use models.FileField for local file or models.CharField for entering URL, depends on an option which were switched before. The next code does not work, but shows the idea:

class T(models.Model):
    action = models.ForeignKey(Action)
    type = models.ForeignKey(Type)
    if type == 2:
        attachment = models.FileField(upload_to=settings.ATTACHEMENTS_FOLDER, blank=True, max_length=255)
    else:
        attachment = models.CharField(blank=True, max_length=255)
1

There are 1 answers

4
Rob L On

You should store it with in the Type model. That way it can be whatever field is correct. And you have flexibility of adding more types later.