Sunday 15 September 2013

python - Django get foreign key data within views.py -


I'm starting with the development of the dynamic and I'm getting some values. This should be simple in my mind.

I have many models, but I have difficulty getting the area (county) from this area in my thoughts. Below I have a very small sample of the event code (if you want to ask more, is not really relevant).

  Category events (models.Model): Organizer = Model. ) Etc ...   

The problem: A single event can be publicized in many areas (limited to event type). To make sure that this is not many for many people, I have defined an event county below: class developments (model.model): county = model.aagarini (county ) Event = Model Event)

Now lies in the idea of ​​this problem, I recently added 5 for my index page and want to show 5 upcoming events. It's really simple because I can order through events in date_added and event_date areas. However, I really do not know how to use the county with this data.

I am convinced that I can only write my own SQL statement (it is easy). However, if possible, I would like to be inside the Denggo frame and use their code I believe That I have to translate something in the statement given below (this may or may not work!) Select the county from the event county, where the event (listevents);

/ div>

As you define that an event can occur in many counties, the event object has set county

  can be accessed as event_obj.county_set.all ()   

. County_set () is related admin / so you can do .filter () , .get () and so on.

No comments:

Post a Comment