Add simple form to edit a wish
This commit is contained in:
parent
ce3684fe67
commit
95cf14c5df
|
@ -0,0 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Editer {{ wish.name }}</h3>
|
||||
<form action="{{ action }}" method="POST">
|
||||
{% csrf_token %}
|
||||
<ul>
|
||||
{{ form.as_ul }}
|
||||
</ul>
|
||||
<input id="save_wish" type="submit" value="Save" />
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
import uuid
|
||||
|
||||
|
@ -45,6 +46,9 @@ class Wish(AbstractModel):
|
|||
percentage = (number_of_linked_parts / total)
|
||||
return percentage * 100
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('wish:wish', kwargs={'pk': self.id})
|
||||
|
||||
|
||||
class WishPart(models.Model):
|
||||
|
||||
|
|
|
@ -17,10 +17,11 @@ Including another URLconf
|
|||
"""
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import WishListList, WishListDetail, WishDetail
|
||||
from .views import WishListList, WishListDetail, WishDetail, UpdateWishView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', WishListList.as_view(), name='wishlists'),
|
||||
url(r'^list/(?P<pk>\d+)/$', WishListDetail.as_view(), name='wishlist'),
|
||||
url(r'^wish/(?P<pk>\d+)/$', WishDetail.as_view(), name='wish'),
|
||||
url(r'^wish/(?P<pk>\d+)/edit$', UpdateWishView.as_view(), name='wish-edit'),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# wish/views.py
|
||||
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic import ListView, DetailView, UpdateView
|
||||
|
||||
from .models import Wish, Wishlist
|
||||
|
||||
|
@ -19,3 +19,9 @@ class WishDetail(DetailView):
|
|||
context_object_name = 'wish'
|
||||
model = Wish
|
||||
template_name = 'wish/wish_detail.html'
|
||||
|
||||
class UpdateWishView(UpdateView):
|
||||
model = Wish
|
||||
fields = ('name', 'description')
|
||||
template_name = 'wish/wish_update.html'
|
||||
|
||||
|
|
Loading…
Reference in New Issue