django model problem
Dave Angel
davea at dejaviewphoto.com
Sat Apr 4 07:52:55 EDT 2009
Mark wrote:
>> I think the first thing you need to do is decide if there is going to be
>> more than one Musician object. and more than one Album object.
>> Presently you are giving all musicians the same first_name and
>> last_name. I suggest you look up the documentation for the special
>> method __init__()
>>
>> Then you need to realize that assigning new attributes to an instance
>> object needs to be done inside an instance method, either __init__() or
>> some other method with a self parameter.
>>
>
>
> What you say would normally make sense, but it's Django and it works that
> way here. See:
> http://docs.djangoproject.com/en/dev/topics/db/models/#fields
>
>
> Regards
> MS
>
>
Sorry, somehow I missed the subject line. I have no experience with
Django, but once I got your message, I read a little of the
introduction. Apparently the static fields in a class in models.py are
treated specially, and describe rows of the database, and the
relationships between those rows. Then I guess Django generates the
necessary instance attributes and methods to make it live.
If I had to guess, I'd say your redundant fields were caused by you
defining a one-to-one relationship between objects that already had a
many-to-one relationship. Presumably there's already a method (or
attribute) to get a list of albums from musician object. You might
better just add a date field to the Album class, and make a method or
function to sort that list.
Anyway, since I don't have time to actually install and configure Django
to experiment, I'd suggest you post a query on the django-users mailing
list, at http://groups.google.com/group/django-users
Sorry I couldn't be more help.
DaveA
More information about the Python-list
mailing list