Discussion:
How to access the Album's ID in the Songs Class??
(too old to reply)
Sourajit Mohanty
2018-12-05 03:50:21 UTC
Permalink
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
--
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.
Saurabh Agrawal
2018-12-05 03:54:50 UTC
Permalink
I think you can use "self.album.id" or "self.album_id".
Post by Sourajit Mohanty
artist=models.CharField(max_length=250)
title=models.CharField(max_length=500)
album=models.ForeignKey(Album,on_delete=models.CASCADE)
song_title=models.CharField(max_length=250)
//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
--
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
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.
--
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/CAL1UH0v35yeCDAoFkQZk1JkYrc59vMOMZ9sjx5sS3A9QZvPNiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...