Hello there

I've got an event model, which has an association with multiple
workshops

models.py
class Event(models.Model):
workshops = models.ManyToManyField(Workshop,
related_name='evt_workshop', limit_choices_to = {'lang_code__in':
('B', 'E')}, blank=True, null=True)

I've got a form that I then use to create the email, with the view

forms.py
class EventBookForm(ModelForm):
workshops = MultipleChoiceField()

views.py
def event_book(request,edate, slug):
I run through some logic here based on request type, and put together
the email that sends off the selected items
I also throw data back to the form, like this
eventdetail = Event.objects.filter(slug=ventslug,start_date=ventdate)
        for d in eventdetail:
                workshopid = d.id
        workshop = Workshop.objects.filter(evt_workshop=workshopid)
        cats = formextra.objects.all()
        context = Context({'form': form, 'cats': cats, 'eventdetail':
eventdetail, 'workshop': workshop })
        return render_to_response('forms/eventbookform.html', context,
context_instance=RequestContext(request))


My problem is this

I can't find a way to list the workshops that are associated with the
event AND send which ones are selected in the tick boxes in the email.

I can list the workshops that are associated with the event in the
view

workshops = Workshop.objects.filter(evt_workshop=d.id)
                        workshoptitlearray = ''
                        for w in workshops:
                                workshoptitle = w.title
                                workshoptitlearray = workshoptitlearray + ', ' 
+ w.title

I think I need to do something like this in the form though, in order
to send the items that have been selected

class EventBookForm(ModelForm):
        workshops = MultipleChoiceField()
        requirements = CharField(widget=Textarea(attrs={'rows': 5, 'cols':
80}))

        class Meta:
                model = Event

        def __init__(self, *args, **kwargs):
                self.request = kwargs.pop('request', None)
                super(EventBookForm, self).__init__(*args, **kwargs)
                workshop_choices = []
                data = Workshop.objects.all()
                print data
                for d in data:
                        workshop_choices.append((d.title,d.title))
        
self.fields['workshops']=MultipleChoiceField(widget=CheckboxSelectMultiple,
choices=workshop_choices, required=False)

As you can see, I'm getting myself into a bit of a mess here, if
anyone can shed any light on how I access the information passed from
the view

context = Context({'form': form, 'cats': cats, 'eventdetail':
eventdetail, 'workshop': workshop })
return render_to_response('forms/eventbookform.html', context,
context_instance=RequestContext(request))

Any help, greatly appreciated, as always




-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to