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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:47:03+00:00 2026-05-31T11:47:03+00:00

I Am trying to give an uploaded image a nicer path, using this code

  • 0

I Am trying to give an uploaded image a nicer path, using this code (in models.py):

def get_image_path_photos(instance, filename):
return os.path.join('photos', str(instance.someproperty), filename)

and the model

class Photo(models.Model):
someproperty = models.CharField(max_length=17, blank=False, null=False, default="something")
photo = models.ImageField(upload_to=get_image_path_photos, blank=True, null=True)

When I save this after a new insert, it saves it in the path /photos/something/ (it keeps using the default value).
When I edit it, add a photo and save it, it will save it to the correct path.
So it must have something to do that while saving the new object, it doesn’t exist yet.

I tried the same with instance.id and this keeps being None as well (I read using auto increment on the id solves this, but this sounds as using the default value as well, and using the default pk/id is auto increment).

I found some simular questions, but none with the answer that solves my problem.

I thought of going to use the pre_save signal…. but somehow my guts says this isn’t the right way.

The solution of my problem I found out myselve, please see my answer… A good lesson, don’t use slugname definitions the same as the field name…..

  • 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-31T11:47:05+00:00Added an answer on May 31, 2026 at 11:47 am

    Sorry about this. The problem is a bit more complicated. I use the field someproperty also in the url as a slug on the posts….
    I just found out something I didn’t expected.

    i did my post (using django rest framework) from the url using the default value in the url… but I filled in the field with something else.

    than, because I define the slugname the same as the fieldname, it overwrites anything you fill in in the field with the value from the url….
    This isn’t exactly what I meant to be done, but makes sence.

    Probably the solution is to call the slug name not the same as the field name……

    I keep this question and answer anyway, because for me it was quite a puzzle….. (might be of help to somebody)

    as an addition to the answer of jpic:
    I used the urls in django rest framwwork, lets say; http:\someurl\api\photos\\
    and post there the photo.

    posting the photo avatar_big.png using someproperty=bar:

    saved the photo in photos\something\ when using the url http\someurl\api\photos\something

    and saved the photo in photos\bar\ when using the url http:\someurl\api\photos\bar

    the problem is (i guess, still have to check this) that the slug name I use for the url is the same as the fieldname.

    this is the code I use in views.py (class based view I use in the django-rest-framework):

    class PhotoBySomePropertyListOrCreateModelView(ListOrCreateModelView):
    permissions = (IsAuthenticated, )
    form = PhotoForm
    def get_queryset(self):
        someproperty=self.kwargs['someproperty']
        return Photo.objects.filter(someproperty=someproperty)
    

    and in urls.py:

    url(r'^api/photos/(?P<someproperty>[\w:]+)/$', PhotoBySomePropertyListOrCreateModelView.as_view(resource=PhotoResource)),
    

    here you see the problem, it doesn’t listen to the field in ‘someproperty’, but to the value in the url ….

    changing it in
    url(r’^api/photos/(?P[\w:]+)/$’, PhotoBySomePropertyListOrCreateModelView.as_view(resource=PhotoResource)),

    should do the trick…. also adjust the view of course

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

Sidebar

Related Questions

I am trying to give the effect of general headings in this table and
I've got the following situation: <h2>This text is <span>pretty awesome</span></h2> I'm trying to give
I'm trying to rescale uploaded jpeg in asp.net So I go: Image original =
I'm basically trying to give rubberbanding effect to my drawing, I'm using the setCompositionMode
Ive been trying to give style to button, The code that I ve used
Some videos uploaded to facebook using iOS Facebook SDK give me the error An
I'm trying to give my plugin callback functionality, and I'd like for it to
I haven't used Visual Studio since VB 3 and am trying to give it
I'm trying to format a string to give me 2 characters for a number,
What I'm trying to do is give my user 4 options (simple links). If

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.