Hi. A quick solution would be to add a datefield to the album the release date. You could then use that to find the latest and it would be updated automatically when adding new albums. You could use ot for other things as well, but I don't know your needs. Will also make the lookup a bit slower but shouldn't be that bad.
~Jakob On Apr 3, 10:14 pm, Albert <fretka1...@gmail.com> wrote: > Hi, > > Say I have these simple models: > > class Musician(models.Model): > first_name = models.CharField(max_length=50) > last_name = models.CharField(max_length=50) > > class Album(models.Model): > artist = models.ForeignKey(Musician) > name = models.CharField(max_length=100) > > Now in `Musician` I want to add a field "last_album". > How can I do that? I'd like to be able to write: > > m = Musician(pk=1) > print m.last_album.name > > When I try: > last_album = models.OneToOneField(Album) > > it somehow works but creates a (useless) unique index for last_album. > And I don't need additional related field in the Album model (it's > also > created now). > > Thanks for help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---