0

I've looked into the answers posted to similar questions but I couldn't get anything to work for my situation, so I will post my question. The way I have it, I always get the result "None" when I try to get the first name of the user who created an event... So I have multiple classes of users and I want to allow one type of user to be able to schedule events, with the template showing the user who created the event along with the various other fields that are in the class relating to the event. So for example:

#models.py

class BaseProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    first_name = models.CharField(max_length=20, verbose_name=_('First Name'))
    last_name = models.CharField(max_length=20, verbose_name=_('Last Name'))
    ...
    #More common fields

#Used for when a new broadcaster registers; fields specific to broadcasters
classBroadcasterProfile(models.Model):
    user_type = models.CharField(max_length=20, default="broadcaster")
    ...
    #Other fields specific to broadcasters

#Used when a broadcaster creates a profile for themselves after they have registered
class BroadcasterAccountProfile(BroadcasterProfile):
    ...

#A broadcaster wants to schedule an event
class UpcomingEvents(models.Model):
    title = models.CharField(max_length=50, verbose_name=_('Title'))
    description = models.TextField(max_length=100, verbose_name=_('Event Description'))
    instructor = models.ForeignKey(BroadcasterAccountProfile, null=True, blank=True, related_name='instructor')
    event_date = models.DateField(auto_now=False, auto_now_add=False, verbose_name=_('Date of Event'))
    ...
    #Additional info to be included with the scheduling of event

So after a broadcaster has registered, created a profile, and scheduled an event (which all works successfully), the view I am trying to use for displaying the upcoming scheduled events is as follows:

#views.py
def upcoming_event_list(request):
    today = datetime.date.today()
    tomorrow = datetime.date.today() + datetime.timedelta(days=1)
    todays_events = UpcomingEvents.objects.filter(event_date=today)
    tomorrows_events = UpcomingEvents.objects.filter(event_date=tomorrow)
    return render_to_response('events/preview.html', {'today': today, 'tomorrow': tomorrow,
    ...

I can have my template display anything related to the upcoming events except for anything related to the broadcaster who created the event. I have tried adding values to my views:

def upcoming_event_list(request):
    ...
    values = UpcomingEvents.objects.values('instructor__first_name', 'instructor__last_name', 'instructor__avatar')

#template.html
{% for v in values %}
    Broadcaster Name:{{ v.instructor__first_name }}
{% endfor %}

This would show "Broadcaster Name: None". Am I completely heading in the wrong direction, or what can I do to try to make this work? Sorry if this was confusing. I tried to make it as clear as possible, but seeing as how I am confused myself, I don't know how successful I was in trying to describe my problem. Thanks for any help. Please let me know if I need to clarify anything.

GetItDone
  • 566
  • 7
  • 22

1 Answers1

0

Have you tried {{ v.instructor.first_name }} in your template?

Note the .(full-stop/dot/period/whatever-you-call-it) instead of a __(double underscore).

meshy
  • 8,470
  • 9
  • 51
  • 73
  • I had tried that, and it didn't work. I finally came up with a solution that works at least for now, but I'm not sure it's the best way to do it. Thanks for the help though. I know I didn't do the best job of explaining my question. – GetItDone Sep 17 '12 at 11:48
  • Could you explain the answer for future readers of this question? – meshy Sep 17 '12 at 13:14
  • 1
    What I ended up doing to get it to work is in my template, instead of {{ v.instructor.first_name }} or {{ v.instructor__first_name }}, I was able to use {{v.instructor.get_profile.first_name }}. – GetItDone Sep 19 '12 at 20:29