UdateView Issues

31 views
Skip to first unread message

Michael Martin

unread,
Sep 17, 2014, 5:42:34 AM9/17/14
to django...@googlegroups.com
I was looking into the generic views that existed and I hoping that this view would work for me.  I expect that the view will display current model as an editable form.  But I am having issues, I get some odd exception.  Can someone that has experience please help me?





UpdateView

class django.views.generic.edit.UpdateView

A view that displays a form for editing an existing object, redisplaying the form with validation errors (if there are any) and saving changes to the object. This uses a form automatically generated from the object’s model class (unless a form class is manually specified).

Ancestors (MRO)

This view inherits methods and attributes from the following views:

Attributes

template_name_suffix

The UpdateView page displayed to a GET request uses a template_name_suffix of '_form'. For example, changing this attribute to '_update_form' for a view updating objects for the example Author model would cause the default template_name to be 'myapp/author_update_form.html'.

object

When using UpdateView you have access to self.object, which is the object being updated.

Example myapp/views.py:

from django.views.generic.edit import UpdateView
from myapp.models import Author

class AuthorUpdate(UpdateView):
    model = Author
    fields = ['name']
    template_name_suffix = '_update_form'

Example myapp/author_update_form.html:

<form action="" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Update" />
</form>


__init__() takes exactly 1 argument (2 given)
Request Method: GET
Request URL: http://127.0.0.1:8080/gateway/config/generalconfig/
Django Version: 1.7.1
Exception Type: TypeError
Exception Value:
__init__() takes exactly 1 argument (2 given)
Exception Location: C:\jython2.7b2\Lib\site-packages\django-1.7.1-py2.7.egg\django\core\handlers\base.py in get_response, line 111
Python Executable: None
Python Version: 2.7.0
Python Path:
['C:\\Users\\mike\\workspace\\ciscoebondinggateway',
 'C:\\Users\\mike\\workspace\\ciscoebondinggateway',
 'C:\\Users\\mike\\workspace\\lwc\\lib\\postgresql-9.3-1102.jdbc41.jar',
 'C:\\jython2.7b2\\Lib\\site-packages\\setuptools-5.7-py2.7.egg',
 'C:\\jython2.7b2\\Lib\\site-packages\\pip-1.5.6-py2.7.egg',
 'C:\\jython2.7b2\\Lib\\site-packages\\django_jython-1.7.0b2-py2.7.egg',
 'C:\\jython2.7b2\\Lib\\site-packages',
 'C:\\jython2.7b2\\Lib',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\resources.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\rt.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\jsse.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\jce.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\charsets.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\jfr.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\access-bridge-32.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\dnsns.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\jaccess.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\localedata.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\sunec.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\sunjce_provider.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\sunmscapi.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\sunpkcs11.jar',
 'C:\\Program Files (x86)\\Java\\jre7\\lib\\ext\\zipfs.jar',
 'C:\\jython2.7b2\\Lib\\site-packages\\django-1.7.1-py2.7.egg',
 '__classpath__',
 '__pyclasspath__/']
Server time: Wed, 17 Sep 2014 02:23:28 -0700

Collin Anderson

unread,
Sep 17, 2014, 11:16:57 AM9/17/14
to django...@googlegroups.com
are you calling as_view() when installing your view in urls.py?

Could you post the rest of the traceback?

Michael Martin

unread,
Sep 17, 2014, 12:52:10 PM9/17/14
to django...@googlegroups.com
Collin,

You are right I was missing the .as_view()

I am now getting an exception:
Exception Value:
Generic detail view GeneralConfigurationUpdate must be called with either an object pk or a slug.


I looked at the example here and I don't see anything mentioning setting up a slug.  I believe a slug is when a previous url redirects with a value attached such as (?P<pk>[0-9]+)

Does this mean that I have to create an additional view to pass the object that I am interested in?



On Wed, Sep 17, 2014 at 8:16 AM, Collin Anderson <cmawe...@gmail.com> wrote:
are you calling as_view() when installing your view in urls.py?

Could you post the rest of the traceback?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/86cd4f96-f6ed-4e79-a35a-e8a27e3cbd79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lachlan Musicman

unread,
Sep 17, 2014, 7:53:45 PM9/17/14
to django...@googlegroups.com
Show us the URLs - the update url requires either a slug OR a pk - one is sufficient, so you don't need to set up a slug. But the update cbv can only be called from an object's url (the one that you would like to update) - it can't be called from just anywhere.

cheers
L.


For more options, visit https://groups.google.com/d/optout.



--
You have to be really clever to come up with a genuinely dangerous thought. I am disheartened that people can be clever enough to do that and not clever enough to do the obvious thing and KEEP THEIR IDIOT MOUTHS SHUT about it, because it is much more important to sound intelligent when talking to your friends.
This post was STUPID.
-----------------------------------------------------------------------------------------------------------
The Most Terrifying Thought Experiment of All Time http://www.slate.com/articles/technology/bitwise/2014/07/roko_s_basilisk_the_most_terrifying_thought_experiment_of_all_time.html
Reply all
Reply to author
Forward
0 new messages