You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
I am able to upload images to my Picture object with portfolio id created earlier.
But i cannot list images according to portfolio id.
I am trying to get Id of an portfolio from my view and i couldn't.
I just want to display images according to my Picture object with portfolio id .
These are my models
class Portfolio(models.Model):
title = models.CharField(max_length=55)
description = models.TextField()
user = models.ForeignKey(User)
class Picture(models.Model):
"""This is a small demo using just two fields. The slug field is really not
necessary, but makes the code simpler. ImageField depends on PIL or
pillow (where Pillow is easily installable in a virtualenv. If you have
problems installing pillow, use a more generic FileField instead.
"""
# portfolio_id = models.ForeignKey(Portfolio,null=True)
file = models.ImageField(upload_to="pictures")
slug = models.SlugField(max_length=50, blank=True)
# user = models.ForeignKey(User, default=1)
portfolio = models.ForeignKey(Portfolio, null=True)
def __str__(self):
return self.file.name
@models.permalink
def get_absolute_url(self):
return ('upload-basic-plus', )
def save(self, *args, **kwargs):
self.slug = self.file.name
super(Picture, self).save(*args, **kwargs)
def delete(self, *args, **kwargs):
"""delete -- Remove to leave file."""
self.file.delete(False)
super(Picture, self).delete(*args, **kwargs)
Sorry for my late reply. I was hoping you found out of the problem by yourself, since your problem is not directly related to the upload code (your code was storing the portfolio_id to the database) - more like how pictures and portfolios are connected and how you get Django to do what you want.
You posted a lot of details, but I'm not going to try to reproduce your problem, in that case, I would prefer to get a link to a repo with all the code, so I could easily try it by myself.
Also missing in your report is the actual error message if there are any. It is kind of hard to guess what you mean. If I were you, I would start with a new view, to show the portfolio, then get all related pictures using portfolio.get_picture_set.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I am able to upload images to my Picture object with portfolio id created earlier.
But i cannot list images according to portfolio id.
I am trying to get Id of an portfolio from my view and i couldn't.
I just want to display images according to my Picture object with portfolio id .
These are my models
These are my urls
These three also my views
The text was updated successfully, but these errors were encountered: