NO

just image add new seed in admin

upload a file with status "UNAPPROVE"
then you change its status as "ACCET"
the problem is, the file you upload is still point to UNAPPROVE_PATH

how to make it point to ACCEPT_PATH ?

On 8月3日, 下午6时45分, Peter Bengtsson <pete...@gmail.com> wrote:
> Not sure I understand what you want to achive but you talked about
> changing one class attribute when you change another.
> Look at this for example/inspiration::
>
> class Foo(object):
>     status = ''
>
>     def __init__(self):
>         self.name = ''
>
>     def __setattr__(self, k, v):
>         if k == 'status':
>             self.name = v.lower()
>         super(Foo, self).__setattr__(k, v)
>
> f = Foo()
> f.status = 'APPROVE'
> print f.status # will print 'APPROVE'
> print f.name  # will print 'approve'
>
> On 3 Aug, 08:28, Shuge Lee <shuge....@gmail.com> wrote:
>
>
>
> > Please take a lookhttp://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
-~----------~----~----~----~------~----~------~--~---

Reply via email to