Saturday, June 30, 2012

Re: invalid keyword argument for this function

This is a different error, and I don't see anything in the code snippet that might have caused this error (except if you are doing something in the Event model's save method)

You would need to debug it further, and pinpoint the location of this error.

On Saturday, June 30, 2012 8:37:34 PM UTC+5:30, Nikhil Verma wrote:
Yes its with the braces ")" also.

On Sat, Jun 30, 2012 at 8:36 PM, Nikhil Verma <varma.nikhil22@gmail.com> wrote:
Hi Sunny

I am trying with this

            event_genre = event_form.cleaned_data['event_genre']
            event_public = event_form.cleaned_data['event_public']
            event_obj.save()

            category_obj.event_genre.add(event_genre),
      category_obj.event_public.add(event_public



and getting this traceback:-


Exception Type: TypeError at /event/createevent/
Exception Value: int() argument must be a string or a number, not 'QuerySet'


On Sat, Jun 30, 2012 at 8:30 PM, Sunny Nanda  wrote:
Hi Nikhil,

Just to reiterate :), you need to remove both event_public & even_genre while creating the instance of the model, since both of them are M2M Fields. Take a look at the example in my previous mail.

If you are getting this exception somewhere else, please send that code snippet so we might able to see the problem.

Thanks,
Sandeep


On Saturday, June 30, 2012 8:14:28 PM UTC+5:30, Nikhil Verma wrote:
Hi Sunny

I realized that earlier sunny, and cleared that defect but i get stuck into this error

Traceback:

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

Any help ?

Thanks in advance


On Sat, Jun 30, 2012 at 7:08 PM, Sunny Nanda  wrote:

Hi Nikhil,

You can not use an object's M2M field until it has been saved to the db.
So, you would have to call the "save" method on the instance, or use "create" method to create the instance.
            category_obj = Category.objects.create(
                            type = categoryform.cleaned_data['type']
                            )
            event_public = categoryform.cleaned_data['event_public']
            event_genre = categoryform.cleaned_data['event_genre']
            category_obj.event_genre.add(event_genre),
            category_obj.event_public.add(event_public),
            # No need to call save here
            # category_obj.save() 

The reason behind this is that M2M Fields are represented by intermediate tables with references to the two linked objects. If you need to add a row in it, both referenced objects should already be saved in the db with valid primary keys.

H2H
-Sandeep


On Saturday, June 30, 2012 1:21:30 PM UTC+5:30, Nikhil Verma wrote:
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9y6fVygzELMJ.
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.



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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/zrcm159aC3YJ.

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.



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




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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Ft4a4VmU_sgJ.
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.

Handling millions of rows + large bulk processing (now 700+ mil rows)

Hi all,

As some of you know, I did a live webcast last year (July 2011) on our LLG project, which explained how we overcome some of the problems associated with large data processing.

After reviewing the video, I found that the sound quality was very poor, the slides weren't very well structured, and some of the information is now out of date (at the time it was 40mil rows, now we're dealing with 700+mil rows).

Therefore, I'm considering doing another live webcast (except this time it'll be recorded+posted the next day, the stream will be available in 1080p, it'll be far better structured, and will only last 50 minutes).

The topics I'd like to cover are:

* Bulk data processing where bulk_insert() is still not viable (we went from 30 rows/sec to 8000 rows/sec on bulk data processing, whilst still using the ORM - no raw sql here!!)
* Applying faux child/parent relationship when standard ORM is too expensive (allows for ORM approach without the cost)
* Applying faux ORM read-only structure to legacy applications (allows ORM usage on schemas that weren't properly designed, and cannot be changed - for example, vendor software with no source code).
* New Relic is beautiful, but expensive. Hear more about our plans to make an open source version.
* Appropriate use cases for IAAS vs colo with SSDs.
* Percona is amazing, some of the tips/tricks we've learned over.

If you'd like to see this happen, please leave a reply in the thread - if enough people want this, then we'll do public vote for the scheduled date.

Cheers

Cal

--
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.

Re: invalid keyword argument for this function

Yes its with the braces ")" also.

On Sat, Jun 30, 2012 at 8:36 PM, Nikhil Verma <varma.nikhil22@gmail.com> wrote:
Hi Sunny

I am trying with this

            event_genre = event_form.cleaned_data['event_genre']
            event_public = event_form.cleaned_data['event_public']
            event_obj.save()

            category_obj.event_genre.add(event_genre),
      category_obj.event_public.add(event_public



and getting this traceback:-


Exception Type: TypeError at /event/createevent/
Exception Value: int() argument must be a string or a number, not 'QuerySet'


On Sat, Jun 30, 2012 at 8:30 PM, Sunny Nanda <snanda85@gmail.com> wrote:
Hi Nikhil,

Just to reiterate :), you need to remove both event_public & even_genre while creating the instance of the model, since both of them are M2M Fields. Take a look at the example in my previous mail.

If you are getting this exception somewhere else, please send that code snippet so we might able to see the problem.

Thanks,
Sandeep


On Saturday, June 30, 2012 8:14:28 PM UTC+5:30, Nikhil Verma wrote:
Hi Sunny

I realized that earlier sunny, and cleared that defect but i get stuck into this error

Traceback:

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

Any help ?

Thanks in advance


On Sat, Jun 30, 2012 at 7:08 PM, Sunny Nanda  wrote:

Hi Nikhil,

You can not use an object's M2M field until it has been saved to the db.
So, you would have to call the "save" method on the instance, or use "create" method to create the instance.
            category_obj = Category.objects.create(
                            type = categoryform.cleaned_data['type']
                            )
            event_public = categoryform.cleaned_data['event_public']
            event_genre = categoryform.cleaned_data['event_genre']
            category_obj.event_genre.add(event_genre),
            category_obj.event_public.add(event_public),
            # No need to call save here
            # category_obj.save() 

The reason behind this is that M2M Fields are represented by intermediate tables with references to the two linked objects. If you need to add a row in it, both referenced objects should already be saved in the db with valid primary keys.

H2H
-Sandeep


On Saturday, June 30, 2012 1:21:30 PM UTC+5:30, Nikhil Verma wrote:
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9y6fVygzELMJ.
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.



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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/zrcm159aC3YJ.

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.



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




--
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.

Re: invalid keyword argument for this function

Hi Sunny

I am trying with this

            event_genre = event_form.cleaned_data['event_genre']
            event_public = event_form.cleaned_data['event_public']
            event_obj.save()

            category_obj.event_genre.add(event_genre),
      category_obj.event_public.add(event_public



and getting this traceback:-

Exception Type: TypeError at /event/createevent/
Exception Value: int() argument must be a string or a number, not 'QuerySet'

On Sat, Jun 30, 2012 at 8:30 PM, Sunny Nanda <snanda85@gmail.com> wrote:
Hi Nikhil,

Just to reiterate :), you need to remove both event_public & even_genre while creating the instance of the model, since both of them are M2M Fields. Take a look at the example in my previous mail.

If you are getting this exception somewhere else, please send that code snippet so we might able to see the problem.

Thanks,
Sandeep


On Saturday, June 30, 2012 8:14:28 PM UTC+5:30, Nikhil Verma wrote:
Hi Sunny

I realized that earlier sunny, and cleared that defect but i get stuck into this error

Traceback:

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

Any help ?

Thanks in advance


On Sat, Jun 30, 2012 at 7:08 PM, Sunny Nanda  wrote:

Hi Nikhil,

You can not use an object's M2M field until it has been saved to the db.
So, you would have to call the "save" method on the instance, or use "create" method to create the instance.
            category_obj = Category.objects.create(
                            type = categoryform.cleaned_data['type']
                            )
            event_public = categoryform.cleaned_data['event_public']
            event_genre = categoryform.cleaned_data['event_genre']
            category_obj.event_genre.add(event_genre),
            category_obj.event_public.add(event_public),
            # No need to call save here
            # category_obj.save() 

The reason behind this is that M2M Fields are represented by intermediate tables with references to the two linked objects. If you need to add a row in it, both referenced objects should already be saved in the db with valid primary keys.

H2H
-Sandeep


On Saturday, June 30, 2012 1:21:30 PM UTC+5:30, Nikhil Verma wrote:
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9y6fVygzELMJ.
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.



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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/zrcm159aC3YJ.

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.



--
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.

Re: invalid keyword argument for this function

Hi Nikhil,

Just to reiterate :), you need to remove both event_public & even_genre while creating the instance of the model, since both of them are M2M Fields. Take a look at the example in my previous mail.

If you are getting this exception somewhere else, please send that code snippet so we might able to see the problem.

Thanks,
Sandeep

On Saturday, June 30, 2012 8:14:28 PM UTC+5:30, Nikhil Verma wrote:
Hi Sunny

I realized that earlier sunny, and cleared that defect but i get stuck into this error

Traceback:

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

Any help ?

Thanks in advance


On Sat, Jun 30, 2012 at 7:08 PM, Sunny Nanda  wrote:
Hi Nikhil,

You can not use an object's M2M field until it has been saved to the db.
So, you would have to call the "save" method on the instance, or use "create" method to create the instance.
            category_obj = Category.objects.create(
                            type = categoryform.cleaned_data['type']
                            )
            event_public = categoryform.cleaned_data['event_public']
            event_genre = categoryform.cleaned_data['event_genre']
            category_obj.event_genre.add(event_genre),
            category_obj.event_public.add(event_public),
            # No need to call save here
            # category_obj.save() 

The reason behind this is that M2M Fields are represented by intermediate tables with references to the two linked objects. If you need to add a row in it, both referenced objects should already be saved in the db with valid primary keys.

H2H
-Sandeep


On Saturday, June 30, 2012 1:21:30 PM UTC+5:30, Nikhil Verma wrote:
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9y6fVygzELMJ.
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.



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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/zrcm159aC3YJ.
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.

Re: invalid keyword argument for this function

Hi Sunny

I realized that earlier sunny, and cleared that defect but i get stuck into this error

Traceback:

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

Any help ?

Thanks in advance


On Sat, Jun 30, 2012 at 7:08 PM, Sunny Nanda <snanda85@gmail.com> wrote:
Hi Nikhil,

You can not use an object's M2M field until it has been saved to the db.
So, you would have to call the "save" method on the instance, or use "create" method to create the instance.
            category_obj = Category.objects.create(
                            type = categoryform.cleaned_data['type']
                            )
            event_public = categoryform.cleaned_data['event_public']
            event_genre = categoryform.cleaned_data['event_genre']
            category_obj.event_genre.add(event_genre),
            category_obj.event_public.add(event_public),
            # No need to call save here
            # category_obj.save() 

The reason behind this is that M2M Fields are represented by intermediate tables with references to the two linked objects. If you need to add a row in it, both referenced objects should already be saved in the db with valid primary keys.

H2H
-Sandeep


On Saturday, June 30, 2012 1:21:30 PM UTC+5:30, Nikhil Verma wrote:
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 view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/9y6fVygzELMJ.
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.



--
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.

Re: advantages and disadvantages of Raw sql queries in django

On 30/06/2012 07:36 πμ, vijay shanker wrote:
> hi
> i want to know pros and cons associated with running raw sql queries
> over django's ORM .
> googled it out but couldn find many useful links.
>
>
At some point in the future you may find yourself in a position when you
will need to change the underlying DB engine.
In these cases ORM is a life saver.

This scenario is not far-fetched it is very common actually. I use
sqlite to develop my app, but in the production server I use mysql.
The code is the same, I have to change only 2 lines in settings.py
This makes development very easy and very portable.
I can reproduce my development environment in 10mins (with the use of
pip and virtualenv of course) and start working in a new machine with
minimum hassle.

--
--------------------------------------------------------------
Nick Apostolakis
e-mail: nickapos@oncrete.gr
Web Site: http://nick.oncrete.gr
--------------------------------------------------------------


--
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.