I am starting off with django development and I am stuck getting some values out. In my mind it should be simple.
I have multiple models but I am having difficulty getting the area (county) from the event itself in my views. Below I have a very short sample of the event code (not really relevant however, if you need more just ask).
class Event(models.Model):
organiser = models.ForeignKey(User)
etc...
The problem is a single event can be advertised in multiple areas (limited on the event type). To make sure it's not a many to many I have defined an event county as below:
class EventCounty(models.Model):
county = models.ForeignKey(county)
event = models.ForeignKey(event)
Now the problem lies in the views, for my index page I want to show the 5 recently added and the 5 upcoming events. This is really simple as I can order by the date_added and event_date fields within Event. However, I am not really sure how to access the county from this data.
I am assuming I could just write the sql statement myself (it's simple) however, if possible I would like to stay within the django framework and use their code. I believe the below statement would be something I will need to translate (it may or may not work!).
select county from EventCounty where event in (listevents);
If anybody knows how I can get this to work I will be grateful!
Thanks in advance,
Luke
countyfield in yourEventmodel, rather than creating anEventCountymodel that makes the database larger and slower?