{"id": 8662, "created": "2008-08-29 00:16:02", "changetime": "2011-09-28 16:12:17", "last_pulled_from_trac": "2022-03-06 03:42:50.720441", "stage": "Unreviewed", "status": "closed", "component": "Documentation", "type": null, "severity": null, "version": "dev", "resolution": "fixed", "summary": "Overriding save() raises error when using Model.objects.create()", "description": "It seems that when over writing .save() (and maybe other default methods) you should be accepting *args, **kwargs and passing it along.\r\n\r\nI get an exception when using Model.objects.create():\r\n\r\nTraceback:\r\nFile \"/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py\" in get_response\r\n 86. response = callback(request, *callback_args, **callback_kwargs)\r\nFile \"/home/pjs/site/netlandish/../netlandish/ccproc/views.py\" in order_process\r\n 41. form_data.get('custom', '')\r\nFile \"/home/pjs/site/netlandish/../netlandish/billing/helpers.py\" in build_sale\r\n 48. ip=ip\r\nFile \"/usr/local/lib/python2.5/site-packages/django/db/models/manager.py\" in create\r\n 87. return self.get_query_set().create(**kwargs)\r\nFile \"/usr/local/lib/python2.5/site-packages/django/db/models/query.py\" in create\r\n 311. obj.save(force_insert=True)\r\n\r\nException Type: TypeError at /order/1027/\r\nException Value: save() got an unexpected keyword argument 'force_insert'\r\n\r\nMy custom .save() didn't have anything catching force_insert..\r\n\r\nThe docs don't show this is required.\r\n", "owner": "nobody", "reporter": "pjs", "keywords": null, "easy": 0, "has_patch": 0, "needs_better_patch": 0, "needs_tests": 0, "needs_docs": 0, "ui_ux": 0} {"id": 8663, "created": "2008-08-29 01:07:00", "changetime": "2011-09-28 16:12:17", "last_pulled_from_trac": "2022-03-06 03:42:50.857469", "stage": "Design decision needed", "status": "closed", "component": "Forms", "type": null, "severity": null, "version": "dev", "resolution": "wontfix", "summary": "Inconsistencies/Bug in ModelForm", "description": "When a ModelForm is used to display a form for a Model, the fields defined with a choices option insert a \"-------\" value for the first option when the form is rendered. If you override a field and manually specify the choices for a Select widget, this \"-------\" does not appear as the first choice.\r\n\r\n{{{\r\n# models.py\r\nfrom django.db import models\r\n\r\nMY_CHOICES = (\r\n (0, 'Zero'),\r\n (1, 'One'),\r\n)\r\n\r\nclass MyModel(models.Model):\r\n my_field = models.IntegerField(choices=MY_CHOICES)\r\n}}}\r\n{{{\r\n# forms.py\r\nfrom django import forms\r\nfrom myapp.models import MyModel, MY_CHOICES\r\n\r\nclass MyModelForm(forms.ModelForm):\r\n #my_field = forms.IntegerField(widget=forms.Select(choices=MY_CHOICES))\r\n class Meta:\r\n model = MyModel\r\n}}}\r\nView the HTML for the form with my_field commented out:\r\n{{{\r\n>>> from myapp.forms import MyModelForm\r\n>>> f = MyModelForm()\r\n>>> print f\r\n