Thanks a lot. Missed save_FOO_file in the docs.
On Dec 18, 12:52 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Dec 18, 2007 12:08 PM, Ryan K <[EMAIL PROTECTED]> wrote:
>
> > def save(self, user):
> > if user != self.scheduled_product.teacher:
> > return False
> > media = Media(name=self.cleaned_data['media'].filename,
> > media=self.cleaned_data['media'].content,
> > uploader=user, scope='STC', accessed=0,
> > description=self.cleaned_data['description'])
> > media.save()
>
> You don't pass in the contents of the file to the model's constructor
> like this. Instead, you instantiate the object, *then* save the file.
> Saving a file also saves the object, by default, so you can do it all
> in one pass. Try something like this instead:
>
> def save(self, user):
> if user!= self.schedule_product.teacher:
> return False
> media = Media(name=self.cleaned_data['media'].filename,
> uploader=user, scope='STC', accessed=0,
> description=self.cleaned_data['description'])
> media.save_media_file(self.cleaned_data['media'].filename,
> self.cleaned_data['media'].content)
>
> Here, media.save_media_file() will actually write the file where it
> needs to go, update the model to reflect that location, and save the
> record to the database, all at once.
>
> -Gul
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---