Make each event have an organisation that's not just a free-text field,
authorMagnus Hagander <magnus@hagander.net>
Thu, 25 Feb 2010 15:46:36 +0000 (16:46 +0100)
committerMagnus Hagander <magnus@hagander.net>
Thu, 25 Feb 2010 15:46:36 +0000 (16:46 +0100)
for future ability to have multiple people manage a single event.

pgweb/core/views.py
pgweb/events/forms.py
pgweb/events/models.py

index e910faa26b63220a92a3ed02c4d97fb12ed7d730..10c750574f15e42fd29706d86023373b076d66b4 100644 (file)
@@ -35,7 +35,7 @@ def home(request):
        traininginfo = Event.objects.filter(approved=True, training=True).extra(where=("startdate <= (CURRENT_DATE + '6 Months'::interval) AND enddate >= CURRENT_DATE",)).aggregate(Count('id'), Count('country', distinct=True))
        # can't figure out how to make django do this
        curs = connection.cursor()
-       curs.execute("SELECT * FROM (SELECT DISTINCT(org) FROM events_event WHERE startdate <= (CURRENT_DATE + '6 Months'::interval) AND enddate >= CURRENT_DATE AND approved AND training AND org IS NOT NULL AND NOT org='') x ORDER BY random() LIMIT 3")
+       curs.execute("SELECT * FROM (SELECT DISTINCT(core_organisation.name) FROM events_event INNER JOIN core_organisation ON org_id=core_organisation.id WHERE startdate <= (CURRENT_DATE + '6 Months'::interval) AND enddate >= CURRENT_DATE AND events_event.approved AND training AND org_id IS NOT NULL) x ORDER BY random() LIMIT 3")
        trainingcompanies = [r[0] for r in curs.fetchall()]
 
        return render_to_response('index.html', {
index cafdcbd38b9d63cd8c6a9ef5ce671ca1dd27badb..e830eed001d1fbb471553d92015fb2050de2e795 100644 (file)
@@ -1,8 +1,13 @@
 from django import forms
 
+from pgweb.core.models import Organisation
 from models import Event
 
 class EventForm(forms.ModelForm):
+       def __init__(self, *args, **kwargs):
+               super(EventForm, self).__init__(*args, **kwargs)
+       def filter_by_user(self, user):
+               self.fields['org'].queryset = Organisation.objects.filter(submitter=user)
        class Meta:
                model = Event
                exclude = ('submitter', 'approved', )
index 18c92d450bf39e35a286138c400405d1230353fe..2b00bc4202a4f3fbf7d695150dcd62b1f03e5c1c 100644 (file)
@@ -3,13 +3,13 @@ from django.contrib.auth.models import User
 from datetime import date
 from pgweb.util.bases import PgModel
 
-from core.models import Country
+from core.models import Country, Organisation
 
 class Event(models.Model, PgModel):
        submitter = models.ForeignKey(User, null=False, blank=False)
        approved = models.BooleanField(null=False, blank=False, default=False)
 
-       org = models.CharField(max_length=70, null=False, blank=False)
+       org = models.ForeignKey(Organisation, null=False, blank=False)
        title = models.CharField(max_length=100, null=False, blank=False)
        city = models.CharField(max_length=50, null=False, blank=False)
        state = models.CharField(max_length=50, null=False, blank=True)