Please take a look http://dpaste.com/74606/
or here # in models.py UNAPPROVE = 0 ACCEPT = 1 REJECT = 2 unapprove_path = os.path.join(MEDIA_ROOT, 'unapprove') accept_path = os.path.join(MEDIA_ROOT, 'accept') reject_path = os.path.join(MEDIA_ROOT, 'reject') def get_filepath(instance, filename): i = instance suffix = os.path.splitext(filename)[-1] newfile = osp.join(i.category, i.name + suffix) if i.status == UNAPPROVE: path = os.path.join(unapprove_path, newfile) elif i.status == ACCEPT: path = os.path.join(accept_path, newfile) elif i.status == REJECT: path = os.path.join(reject_path, newfile) return path class Category(models.Model): name = models.CharField(max_length=32, unique=True, null=True) def __unicode__(self): return self.name class Meta: verbose_name_plural = 'Categories' def save(self): self.name = self.name.replace(' ', '-') super(Category, self).save() class Seed(models.Model): name = models.CharField(max_length=128) files = models.FileField(upload_to=get_filepath, blank=True, null=True) category = models.ForeignKey(Category) status = models.IntegerField(max_length=1, choices=SEED_STATUS_CHOICES, default=UNAPPROVE) def __unicode__(self): return self.name def save(self, force_insert=False, force_update=False): self.name = self.name.replace(' ', '-') super(Seed, self).save() However, how to make `files` field be modified automatically while `status` field changed ? """ ================================================================ For example, I add new record from django.core.files import File myfile = File(open('/tmp/old.7z')) t.Seed(name='TCPL', category=Category(pk=1), status=UNAPPROVE) t.files.save(name=t.name, content=myfile) t.save() t.status = ACCEPT # I want t.files changed automatically here # How to do it ? t.save() """ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---