On Apr 3, 11:08 pm, Briel <toppe...@gmail.com> wrote:
> 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.

Hi,

Well, right - I oversimplified my sample model. So the pub_date in
Album model would probably be useful
(pub_date = models.DateField()).

But this is not the issue. Say I don't want access to the *last* album
but to some arbitrary one.
For example the favorite album. In the database it should be just an
id of musician's favorite album.
No extra database indexes are necessary.

A non-django solution would be something like:

class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    favorite_album = models.IntegerField
(db_column='favorite_album_id')

I would somehow update the favorite_album_id field with the id of the
favorite album. That's not the problem.
But this solution has a drawback - the favorite_album is just an
integer. So I can't use the Django's
built-in ORM for it. I would like to be able to write (in my program):

m = Musician(pk=1)
print m.favorite_album.name

Or:

m = Musician(pk=1)
a = Album(id=7)
m.favorite_album = a

Is that possible?

It works when I write this:

class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    last_album = models.OneToOneField(Album,
db_column='last_album_id')

But when Django creates SQLs (via syncdb) it adds a database index for
last_album_id which is completely useless.

So maybe the question should be - can Django create a OneToOneField
without generating a
database index for it?

Regards,
MS

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to