On Wed, Mar 11, 2009 at 5:42 PM, Vincent <jellygr...@gmail.com> wrote:
> > Hi all: > > I am just getting started with Django and could really use some > initial help. My first hurdle is this: I would like to have the act of > choosing a file automatically propagate several of fields of my model. > Bellow is an example of the model of interest here: > > ##models.py > from django.db import models > > class Media(models.Model): > media_name = models.CharField('name', max_length=100) > media_size = models.IntegerField('file size in bytes') > media_hash = models.CharField('SHA1 hash', max_length=40) > media_loc = models.FileField(upload_to='test', > verbose_name="media") > is_active = models.BooleanField('is active?') > add_date = models.DateTimeField('date added', auto_now_add=True) > > class Meta: > verbose_name = "Media File" > > def __unicode__(self): > return self.media_name > return self.media_hash > > The desired behavior is to be able to select a file to upload and have > it validated. Then, either during the validation process or > afterwards, I would like to populate the fields of my model with data > that is detected from the file. Data such as: the file's size, the > file name and an SHA1 hash of the file. > > Just to restate, I would really like to be able to do this from within > the provided admin interface. I am not able to figure out how to even > validate this file from within the admin, let alone perform additional > operations on it. > > Thanks, > > ~Vincent > > > > For additional validation you should provide a custom form: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#form and to set the fields automatically you should use the save_model hook: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-model-self-request-obj-form-change Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---