1. Monwara LLC
  2. Untitled project
  3. django-related


Branko Vukelic  committed 7dd5ca2

Explained difference to stock CreateView

  • Participants
  • Parent commits 99517ea
  • Branches master

Comments (0)

Files changed (1)

File README.rst

View file
 resource. The main assumption is that higher levels of the path contains a slug
 or pk that points to the related model's object.
+The key difference between normal CreateView, which can be persuaded to give
+you the related object using the ``queryset`` attribute and ``get_object``
+method, and this mixin, lies in the form processing. This mixin does two things
+1. It ensures that the related object exists (behavior similar to
+   ``get_object`` is forced)
+2. It attaches the related object to the appropriate field in the submitted
+   object.
 Here is an example::
     from related import CreateWithRelatedMixin
         form_class = CustomAttachmentModelForm
         related_model = Post
-With the above setup, the ``django.http.Http404`` is raised if post with the
-slug as in the URL does not exist. Otherwise, the ``CustomAttachmentModelForm``
+With the above setup, the ``django.http.Http404`` is raised if GET request is
+made to this view with the slug in the URL that points to a non-existent post.
+If POST request is made to the same URL, ``django.http.HttpResponseGone`` (410)
+is returned if post does not exist. Otherwise, the ``CustomAttachmentModelForm``
 is processed, and the ``Post`` object that was found based on the slug will be
 added to ``post`` field of the object resulting from the form processing.
 ``related_404_redirect_url`` (``get_related_404_url()``)
     If specified, the view will redirect instead of raising
-    ``django.http.Http404``. Default is ``None``.
+    ``django.http.Http404`` or returning ``django.http.HttpResponseGone``. 
+    Default is ``None``.
 ``related_404_message`` (``get_rlated_404_message``)
     If ``related_404_redirect_url`` is used, the ``django.contrib.messages`` is