dimanche 29 octobre 2017

Making FileField link through ForeignKey object

How can i create a link to the particular file?

models.py

class Post(models.Model):
    ....

class Presentation(models.Model):
    pres_id = models.AutoField(primary_key=True)
    description = models.CharField(max_length=100)
    upload = models.FileField(upload_to='presentation', null=True)
    def __str__(self):
        return self.description

class Participant(models.Model):
    conference = models.ForeignKey(Post, related_name = 'members', on_delete=models.CASCADE, null=True, blank=True) #Post class
    presentation = models.ForeignKey(Presentation, related_name = 'pres', on_delete=models.CASCADE, null=True, blank=True)

views.py

def post_detail(request, pk):
    post = get_object_or_404(Post, pk=pk)
    return render(request, 'plan/post_detail.html', {'post': post})

post_detail.html



part.presentation returns only Presentation description. But I need also a file link. How can i solve this problem. Thanks.

(Structure: there is a post with information about conference participants, presentations, etc. Presentation descriprion link should open a pdf file in browser)




Aucun commentaire:

Enregistrer un commentaire