Hello,

I'm rather new to Django and I've got a problem with foreign keys and
relationships in the views.py.

Suppose I would like to create a calendar application with multiple
users. There should be the possibility that multiple users are
participant of one appointment.

That is the corresponding models.py:

class Appointment(models.Model):
                description = models.CharField(max_length=50)
                start_timestamp =  models.DateTimeField()
                end_timestamp = models.DateTimeField()

class AppointmentRole(models.Model):
                description = models.CharField(max_length=20)

class AppointmentParticipant(models.Model):
                appointment = models.ForeignKey(Appointment)
                participant_user = models.ForeignKey(User)
                participant_role = models.ForeignKey(AppointmentRole)


My problem is how to retrieve all appointment details in a view for
the current user, suppose he has got the user_id = 1.

The raw SQL statement for that would be:

SELECT a.*, b.*
FROM calendar_appointmentparticipant a
INNER JOIN calendar_appointment b on (a.appointment = b.id)
INNER JOIN calendar_appointmentrole c on (a.participant_role = c.id)
WHERE a.paticipant_user = 1;

I tried select_related etc., but to be true I'm totally stuck.

Perhaps someone can give me a hint how to write the view without using
raw SQL.

Many thanks in advance.

Yours,
Michael
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to