How to access the Album's ID in the Songs Class??

8 views
Skip to first unread message

Sourajit Mohanty

unread,
Dec 5, 2018, 3:50:21 AM12/5/18
to Django users
class Album(models.Model):
artist=models.CharField(max_length=250)
title=models.CharField(max_length=500)

class Song(models.Model):
album=models.ForeignKey(Album,on_delete=models.CASCADE)
song_title=models.CharField(max_length=250)

def get_absolute_url(self):
//I need to access the Album ID from here..so that i can redirect myself to the Album's url after adding a new song

Saurabh Agrawal

unread,
Dec 5, 2018, 3:55:28 AM12/5/18
to django...@googlegroups.com
I think you can use "self.album.id" or "self.album_id".

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/935048ff-94f5-4831-bde0-231a473c0fa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages