Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6235583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:41:39+00:00 2026-05-24T10:41:39+00:00

I am trying to create a system that enables the admin to upload a

  • 0

I am trying to create a system that enables the admin to upload a zipfile, then the script will automatically, using signals, unzip it, search for all the files in jpg,png. create a list of them and generate a database record according to it.

In models, i have Project and Photo table, Photo has Many-to-One aka Foreign Key relationship with Project.

The script below is with the signal i am working. I can get instance.file_zip.path without errors, and the script works well when run manually.

Long-time debugging and I assume that there is something wrong with belongs_to=instance but I do not know how to fix it as I didn’t actually understand why it gaves an error.
The extraction part works fine, I just put them here for reference, most likely you will not need to read and understand it.

@receiver(post_save, sender=Project)
def unzip_and_process(sender, instance, **kwargs):
    #project_zip = FieldFile.open(file_zip, mode='rb')
    file_path = instance.file_zip.path
    file_list = []
    with zipfile.ZipFile(file_path, 'r') as project_zip:
        project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0))
        project_zip.close()
    for root, dirs, files in os.walk(file_path):
        for filename in files:
            file_list.append(os.path.join(root, filename))
    photo_list = filter(filter_photos, file_list)
    for photo in photo_list:
        print 'Processing %s'%photo
        p = Photo.objects.create(belongs_to=instance, img=photo, desc='Processed from zipfile')
        p.save()

update

class Project(models.Model):
    project_name=models.CharField(max_length=150)
    date_taken=models.DateField()
    date_deadline=models.DateField()
    price=models.FloatField()
    price_paid=models.BooleanField()
    owner=models.ForeignKey(User)
    file_zip=models.FileField(upload_to='projects/%Y/%m/%d')

    def __unicode__(self):
        return self.project_name

    def file_path(self):
        return re.search('[^\s]+(?=\.zip)', self.file_zip.name).group(0)

class Photo(models.Model):

    def project_path(instance, filename):
        return '%s/%s'%(instance.belongs_to.file_path(),filename)

    belongs_to=models.ForeignKey(Project, verbose_name="related_project")
    img=models.ImageField(upload_to=project_path, max_length=255)
    desc=models.CharField(max_length=255)

    def __unicode__(self):
        return '%s FROM [%s]'%(self.img.name,self.belongs_to)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:41:40+00:00Added an answer on May 24, 2026 at 10:41 am
    for root, dirs, files in os.walk(file_path):
    

    file_path refers to a zip file. not a directory hence os.walk returns nothing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a basic system that will allow only specific users to
I'm trying to create system users with a php script securely, In that, I'd
Hi I am trying create a system call that will count the number of
im trying to create a restaurant system that will create food items and such
I am trying to create a simple log in system that uses ajax but
I am trying to create a messaging system between users and organizations - that
Heyy Everybody! I am trying to create a memory management system, so that a
I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get
I'm trying to create my first AppWidget using the AlarmManager class so that I
I am trying to create a Windows Application that will be able to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.