Initial StockItem create form value addition

This commit is contained in:
guillaume-renaud 2016-11-11 16:55:52 +01:00
parent 887893fb2d
commit 587ad96326

View File

@ -1,4 +1,4 @@
from django.shortcuts import render from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView, RedirectView, TemplateView from django.views.generic import ListView, DetailView, RedirectView, TemplateView
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -39,7 +39,7 @@ class StockEditForm(forms.ModelForm):
""" """
class Meta: class Meta:
model = Stock model = Stock
fields = ['name'] fields = ['name', 'counter']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(StockEditForm, self).__init__(*args, **kwargs) super(StockEditForm, self).__init__(*args, **kwargs)
@ -80,6 +80,12 @@ class StockItemCreateView(CounterAdminTabsMixin, CanCreateMixin, CreateView):
template_name = 'core/create.jinja' template_name = 'core/create.jinja'
pk_url_kwarg = "stock_id" pk_url_kwarg = "stock_id"
current_tab = "stocks" current_tab = "stocks"
def get_initial(self):
ret = super(StockItemCreateView, self).get_initial()
if 'stock' in self.request.GET.keys():
ret['stock_owner'] = self.request.GET['stock']
return ret
def get_success_url(self): def get_success_url(self):
return reverse_lazy('stock:main', kwargs={'stock_id': self.object.stock_owner.id}) return reverse_lazy('stock:main', kwargs={'stock_id': self.object.stock_owner.id})