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

  • Home
  • SEARCH
  • 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 8107815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:53:51+00:00 2026-06-06T00:53:51+00:00

I am using django-nonrel, Postgre as a database and Mongo as file store. my

  • 0

I am using django-nonrel, Postgre as a database and Mongo as file store.

my Model look like this and is working properly

class Doc(models.Model):
    created_on = models.DateTimeField(auto_now_add=True)
    file = models.FileField(storage=gridfs_storage, upload_to='/')

and is working properly

Doc.objects.all()[0].file.size
108776

Now I am trying to aggregate the size to get the total size of a query set.

I have tried

Doc.objects.all().aggregate(Sum('file__size'))

but this throw

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/zoidberg/dev/backus/lib/python2.6/site-packages/django/db/models/query.py", line 321, in aggregate
    is_summary=True)
  File "/Users/zoidberg/dev/backus/lib/python2.6/site-packages/django/db/models/sql/query.py", line 974, in add_aggregate
    field_list, opts, self.get_initial_alias(), False)
  File "/Users/zoidberg/dev/backus/lib/python2.6/site-packages/django/db/models/sql/query.py", line 1417, in setup_joins
    raise FieldError("Join on field %r not permitted. Did you misspell %r for the lookup type?" % (name, names[pos + 1]))
FieldError: Join on field 'file' not permitted. Did you misspell 'size' for the lookup type?
    enter code here

any idea if that is possible using the ORM or I d have to iterate of the files myself ?

  • 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-06-06T00:53:52+00:00Added an answer on June 6, 2026 at 12:53 am

    It’s impossible to do this with the ORM since it can only generate aggregations against database fields, while file.size is a dynamic attribute provided by the storage backend.

    That said, you’re probably better of saving this information in your actual database at upload time, so you can avoid the overhead of iterating over all files.

    class Doc(models.Model):
        created_on = models.DateTimeField(auto_now_add=True)
        file = models.FileField(storage=gridfs_storage, upload_to='/')
        file_size = models.PositiveIntegerField()
    
        def save(self, *args, **kwargs):
            self.file_size = self.file.size
            super(Doc, self).save(*args, **kwargs)
    

    Now aggregations work as expected since you’re dealing with a database field:

    Doc.objects.all().aggregate(Sum('file_size'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am using django forms on my app. I have a model Client like this:
I have an app using using Django Nonrel on AppEngine. I'd like to use
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
I'm having trouble using Markdown in Django Nonrel. I followed this instructions (added 'django.contrib.markup'
I am using django-nonrel and django-mongodb-engine I have a Django model stored on PostgreSQL
I'm using the django-mongodb-engine, django-nonrel, djangotoolbox projects / packages to get django talking with
I'm using the standard (as opposed to NonRel) version of Django connected to PostgreSQL
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I using Django tagging project. That is was very stable project. Working on django
I am using django-nonrel on the google-app-engine. When I'm posting a foreign character, in

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.