Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will want to wire your URL to the Django <a href="https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-create-update-create-object" rel="nofollow noreferrer">create_object generic view</a>, and pass it either "model" (the model you want to create) or "form_class" (a customized <a href="https://docs.djangoproject.com/en/1.1/topics/forms/modelforms/#topics-forms-modelforms" rel="nofollow noreferrer">ModelForm</a> class). There are a number of <a href="https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-create-update-create-object" rel="nofollow noreferrer">other arguments</a> you can also pass to override default behaviors.</p> <p>Sample URLconf for the simplest case:</p> <pre><code>from django.conf.urls.defaults import * from django.views.generic.create_update import create_object from my_products_app.models import Product urlpatterns = patterns('', url(r'^admin/products/add/$', create_object, {'model': Product})) </code></pre> <p>Your template will get the context variable "form", which you just need to wrap in a &lt;form> tag and add a submit button. The simplest working template (by default should go in "my_products_app/product_form.html"):</p> <pre><code>&lt;form action="." method="POST"&gt; {{ form }} &lt;input type="submit" name="submit" value="add"&gt; &lt;/form&gt; </code></pre> <p>Note that your Product model must have a get_absolute_url method, or else you must pass in the post_save_redirect parameter to the view. Otherwise it won't know where to redirect to after save.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload