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 6754509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:17:22+00:00 2026-05-26T13:17:22+00:00

Using django-filebrowser and the FileBrowserField I am attempting to assign the directory parameter based

  • 0

Using django-filebrowser and the FileBrowserField I am attempting to assign the directory parameter based off a key in the model itself. So using a blog example, if I were saving photos for different posts, the photos would be in directories named after the blog id. So if the MEDIA_ROOT was/some/path/to/media/filebrowser_files/ I wish to dynamically assign the directory paramter to be MEDIA_ROOT+str(model_pk)

At this point I have attempted to do something resembling the following, but do not understand how to obtain the id of the current object. (DoesNotExist exception with “No exception supplied”) I know the error exists within the attempt to use self.page, but I do not know how to do this correctly. Could someone provide some insight as to where my logic is flawed and what I can do to fix it? Thanks much.

class PageImage(models.Model):
    page = models.ForeignKey(Page)
    page_photo = FileBrowseField("Image", max_length=200, blank=True, null=True)
    def __init__(self, *args, **kwargs):
        super(PageImage, self).__init__(*args, **kwargs)
        path = settings.MEDIA_ROOT+'pages/unfiled/'
        if self.page:
            path = settings.MEDIA_ROOT+'pages/'+str(self.page)+'/'
        if not os.path.exists(path):
            os.makedirs(path)
        self._meta.get_field_by_name("page_photo")[0].directory = path
  • 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-26T13:17:22+00:00Added an answer on May 26, 2026 at 1:17 pm

    I realize I didn’t look closer at your code. self.page will not work because you’re initializing the Model instance and self.page has not been set to a page in the database. You should try instead:

    class PageImage(models.Model):
        page = models.ForeignKey(Page)
        page_photo = FileBrowseField("Image", max_length=200, blank=True, null=True)
    
        def save(self, *args, **kwargs):
    
            path = settings.MEDIA_ROOT+'pages/unfiled/'
            if self.page:
                path = settings.MEDIA_ROOT+'pages/'+str(self.page)+'/'
            if not os.path.exists(path):
                os.makedirs(path)
            self._meta.get_field_by_name("page_photo")[0].directory = path
            super(PageImage, self).save(*args, **kwargs)
    

    doing what you want only after you’ve assigned a Page to the field in PageImage.

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

Sidebar

Related Questions

I'm considering using Django for a project I'm starting (fyi, a browser-based game) and
I'm using Django to write a blog app, and I'm trying to implement a
I'm using django-tinymce together with the no grappelli branch of django-filebrowser running django 1.2.
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
This is killing me! I'm using django-filebrowser, and I want to create a gallery
(Using django as an example; the ForeignKey is implicit in the example) >>> from
When using django.contrib.comments is there anyway to add the reverse relationship to a model
Am using django forms on my app. I have a model Client like this:
I'm using Django 1.0.2. I've written a ModelForm backed by a Model. This model

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.