Add motivationterme delete method (model + view)

This commit is contained in:
Christophe Boulanger 2017-02-28 13:30:21 +01:00
parent 35ba3951ea
commit c23b80c613
3 changed files with 18 additions and 8 deletions

View File

@ -15,11 +15,13 @@
<table class="main">
<thead>
<tr><th>{% trans 'Label' %}</th><th>{% trans 'Price' %}</th><th>{% trans 'Description' %}</th></tr>
<tr><th>{% trans 'Label' %}</th><th>{% trans 'Price' %}</th><th>{% trans 'Description' %}</th><th>&nbsp;</th></tr>
</thead>
<tbody>
{% for motivation in object.get_motivation_terms %}
<tr><td>{{motivation.text}}</td><td>{{motivation.price}}</td><td>{{motivation.description}}</td></tr>
<tr><td>{{motivation.text}}</td><td>{{motivation.price}}</td><td>{{motivation.description}}</td>
<td><a rel="popup" href="{% url 'motivationterm-delete' pk=motivation.id connector_slug=object.slug %}">X</a></td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,5 +1,5 @@
from django.conf.urls import patterns, include, url
from .views import DatasourcesView, MotivationtermAddView
from .views import DatasourcesView, MotivationtermAddView, MotivationtermDeleteView
urlpatterns = patterns('',
url(r'^(?P<slug>[\w,-]+)/data$', DatasourcesView.as_view(), name='DatasourcesView-data'),
@ -8,4 +8,6 @@ urlpatterns = patterns('',
management_urlpatterns = patterns('',
url(r'^(?P<connector_slug>[\w,-]+)/motivationterm/add/',
MotivationtermAddView.as_view(), name='motivationterm-add'),
url(r'^(?P<connector_slug>[\w,-]+)/motivationterm/(?P<pk>[\w,-]+)/delete/',
MotivationtermDeleteView.as_view(), name='motivationterm-delete'),
)

View File

@ -1,5 +1,4 @@
# from django.http import HttpResponseRedirect
from django.views.generic import View, CreateView
from django.views.generic import View, CreateView, DeleteView
from django.views.generic.detail import SingleObjectMixin
from django.core.urlresolvers import reverse
@ -8,11 +7,8 @@ from .models import ImioTs1Datasources, MotivationTerm
class DatasourcesView(View, SingleObjectMixin):
model = ImioTs1Datasources
# form_class = DatasourcesForm
# DatasourcesAddView is missing a QuerySet. Define DatasourcesAddView.model,
# DatasourcesAddView.queryset, or override DatasourcesAddView.get_queryset().
class MotivationtermAddView(CreateView):
model = MotivationTerm
fields = '__all__'
@ -23,3 +19,13 @@ class MotivationtermAddView(CreateView):
return reverse('view-connector',
kwargs={'connector': connector.get_connector_slug(),
'slug': connector.slug})
class MotivationtermDeleteView(DeleteView):
model = MotivationTerm
def get_success_url(self):
connector = ImioTs1Datasources.objects.get(slug=self.kwargs['connector_slug'])
return reverse('view-connector',
kwargs={'connector': connector.get_connector_slug(),
'slug': connector.slug})