Saturday, June 30, 2012

invalid keyword argument for this function

Hi All

I have the following models like this :-


class EventGenre(models.Model):
    genre_choices = models.CharField(max_length=255)
   
    def __unicode__(self):
        return self.genre_choices
   
class EventPublic(models.Model):
    choicelist = models.CharField(max_length=255)
  
    def __unicode__(self):
        return self.choicelist

class Category(models.Model):
    """
    Describes the Event Category
    """
   
    type = models.CharField(max_length=20,\
                                  choices=EVENT_TYPE,\
                                  help_text = "type of event"
                                  )
    # Genre of event like classical,rock,pop ,indie etc
    event_genre = models.ManyToManyField(EventGenre)
   
    # audience for this event like adults ,children etc
    event_public = models.ManyToManyField(EventPublic)
   
    def __unicode__(self):
        return self.type

This is my category form

class CategoryForm(forms.Form):
    type = forms.CharField(max_length=80, \
                           widget=RadioSelect(choices=EVENT_TYPE)
                           )
    event_genre = forms.ModelMultipleChoiceField(
                        queryset = EventGenre.objects.all(),
                        widget=CheckboxSelectMultiple,
                        required=False
                        )
    event_public = forms.ModelMultipleChoiceField(
                        queryset = EventPublic.objects.all(),                         
                        widget=CheckboxSelectMultiple,
                        required=False
                        )

This is my views.py

def eventcreation(request):
    if request.method == "POST":
        event_form = EventForm(request.POST,request.FILES,prefix="eventform")
        categoryform = CategoryForm(request.POST)
        if event_form.is_valid():
            event_obj = Event(
            venue_name = event_form.cleaned_data['venue_name'],
            date_created = event_form.cleaned_data['event_start_date'],
            date_completed = event_form.cleaned_data['event_end_date'],
            event_ticket_price = event_form.cleaned_data['event_ticket_price'],
            eventwebsite = event_form.cleaned_data['eventwebsite'],
            keyword = event_form.cleaned_data['keyword'],
            description = event_form.cleaned_data['description'],
            status = event_form.cleaned_data['status'],
            event_poster = event_form.cleaned_data['event_poster']
            )
        if categoryform.is_valid():
            category_obj = Category(
                            type = categoryform.cleaned_data['type'],
                            event_public = categoryform.cleaned_data['event_public'], # It is giving error
                            event_genre = categoryform.cleaned_data['event_genre'],   # It is giving error   
                            )
           
            category_obj.event_genre.add(event_genre),
            category_obj.event_public.add(event_public),
            category_obj.save()
           
           
        else:
            print "Form is getting Invalid"
    else:
      
        event_form = EventForm()
        categoryform = CategoryForm()
    return render_to_response('event/event.html',
                              {
                              'eventform':event_form,
                              'categoryform':categoryform,
                              },
                              context_instance=RequestContext(request)
                              )
           
I am trying to add a ManyToMany Field and gets this traceback :-

Exception Type: TypeError at /event/createevent/
Exception Value: 'event_public' is an invalid keyword argument for this function

Can anybody point out whats going wrong ?

Thanks in advance.


--
Regards
Nikhil Verma
+91-958-273-3156

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

No comments:

Post a Comment