Re: database relationships, many to one

2010-11-21 Thread Bruno Amaral
It Worked :) Thank you both for the guidance. Here's the final result in case it will help anyone else http://dpaste.com/278230/ On Nov 21, 5:09 pm, Carlos Daniel Ruvalcaba Valenzuela wrote: > The first error is simple, university models is defined after your > department model, thus is not fo

Re: database relationships, many to one

2010-11-21 Thread Carlos Daniel Ruvalcaba Valenzuela
The first error is simple, university models is defined after your department model, thus is not found, you can define the foreign key as a string in the form of "appname.ModelName", so you will define it like this: class departments(models.Model): university = models.ForeignKey("appname.unive

Re: database relationships, many to one

2010-11-21 Thread Bruno Amaral
Carlos, Thank you for this! Your solution is what I am looking for,but for some reason I get an error message: "NameError: name 'university' is not defined" Figuring this could an issue with Python and not Django, i added university ='' to the top. The validate comma

Re: database relationships, many to one

2010-11-20 Thread Joseph (Driftwood Cove Designs)
unless a dept. can belong to several Universities (?), Carlos has the right model. On Nov 20, 8:23 pm, Carlos Daniel Ruvalcaba Valenzuela wrote: > Depends on you requirements, you could have used a Foreign Key to the > University on the Department model and marking it as required, thus > there ca

Re: database relationships, many to one

2010-11-20 Thread Carlos Daniel Ruvalcaba Valenzuela
Depends on you requirements, you could have used a Foreign Key to the University on the Department model and marking it as required, thus there cannot be a Department without university and set the related_name property on the ForeignKey to the "departments" so you can access University.departments

Re: database relationships

2008-08-27 Thread nek4life
Yup that did it. I could have sworn I tried that, but I guess not. Thanks again. Charlie On Aug 27, 1:27 pm, lingrlongr <[EMAIL PROTECTED]> wrote: > Try this is the template: > > {% for albumart in album.albumart_set.all %} >     {{ albumart.image }} > {% endfor %} > > On Aug 27, 11:58 am, nek4

Re: database relationships

2008-08-27 Thread lingrlongr
Try this is the template: {% for albumart in album.albumart_set.all %} {{ albumart.image }} {% endfor %} On Aug 27, 11:58 am, nek4life <[EMAIL PROTECTED]> wrote: > Well this works great while using the generic detail view, but when I > return a list view the relationships won't work. > > in

Re: database relationships

2008-08-27 Thread nek4life
Well this works great while using the generic detail view, but when I return a list view the relationships won't work. in my view def album_list(request, page=0): return list_detail.object_list( request, queryset = Album.objects.select_related().all(), paginate_by = 20,

Re: database relationships

2008-08-22 Thread nek4life
Awesome. I got it to work using this code in my view. def artist_detail(request, slug): album_list = Album.objects.all() return list_detail.object_detail( request, queryset = Artist.objects.all(), slug = slug, template_object_name = 'artist', extra

Re: database relationships

2008-08-22 Thread lingrlongr
Also note, if your intentions were to grab all that information and just send the artist to the template, I think you'd get better performance if your queryset in the view looked like this: queryset=Artist.objects.select_related().all() Keith On Aug 22, 11:17 am, lingrlongr <[EMAIL PROTECTED]>

Re: database relationships

2008-08-22 Thread lingrlongr
Super easy :) Just to show you another way to implement generic views, I used custom view that returns a generic view. # urls.py from myapp.views import artist ... (r'^artist/(?P\w+)/$', artist), ... #views.py from django.views.generic.list_detail import object_detail def artist(request, slug):

Re: database relationships

2008-08-22 Thread nek4life
So if I sent the artist to the template and wanted to grab the list of albums with all the album tracks how would I go about that. Would I have to pull in all the data with a custom view? So far I've only been using generic views. It definitely makes sense pulling in the information through the

Re: database relationships

2008-08-21 Thread lingrlongr
One more note. You wouldn't NEED to explicitly grab all those vars, as you can get them in a template too. I just wanted to show you the relation. If you sent the track to the template, you can get the artist by using: {{ track.album.artist }} Keith On Aug 22, 12:24 am, lingrlongr <[EMAIL PRO

Re: database relationships

2008-08-21 Thread lingrlongr
The only part you have that is redundant is the "artist" in your "Track" class. You can find out the artist because a track is related to an album, which in turn, is related to an artist. Some of the code you'd maybe see in a view would be: # views.py from django.shortcuts import get_object_or_