event = Event.objects.filter(org=request.org).select_related("event_def", "location", "space")
and i get smthing like this
1st object
Almaty nights #some event_def inside-->Sary Arka #location inside location-->Hall 7 #place inside place-->3 мая 1991 г. 0:00:00开发者_如何学运维 #Event 2nd object Almaty nights #some event_def inside-->Omega #location inside location-->Hall 2 #place inside place-->6 мая 1991 г. 0:00:00 #Eventi need one event_def and inside multiple locations..etc
event model
org = models.ForeignKey(Organization)
event_def = ChainedForeignKey(EventDef,
chained_field = "org",
chained_model_field = "org",
show_all = False,
auto_choose = True
)
location = ChainedForeignKey(Location,
chained_field = "org",
chained_model_field = "org",
show_all = False,
auto_choose = True
)
space = ChainedForeignKey(Space,
chained_field = "location",
chained_model_field = "location",
show_all = False,
auto_choose = True
)
time = models.DateTimeField()
enabled = models.IntegerField(choices = ns.FULL_ENABLE_STATUSES, default = ns.ENABLED_STATUS)
objects = EnableDisableManager()
Are you saying that you want to be able to get multiple locations for an event? If you do, then your data model is wrong. For an event to have multiple locations, you want to do this:
class Event(models.Model):
org = ...
event_def = ...
space = ...
...
class Location(models.Model):
event = models.ForeignKey(Event, related_name='locations')
...
And then in your template you'll be able to do this:
{{ event }}
{% for location in event.locations %}
{{ location }}
{% endfor %}
精彩评论