Commit d91e6247 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added values to valid function instead of roundabout way with prepopulated...

added values to valid function instead of roundabout way with prepopulated hidden widgets to lookouts
parent 901ee445
......@@ -16,7 +16,6 @@ class LookoutForm( forms.ModelForm ):
self.helper.layout = Layout(
Fieldset("",
'owner',
Field('isbn', placeholder='0801884039'),
HTML("""<hr/ >"""),
FormActions(
......@@ -30,5 +29,4 @@ class LookoutForm( forms.ModelForm ):
class Meta:
model = Lookout
include = ('owner', 'isbn',)
......@@ -7,26 +7,25 @@ from braces.views import LoginRequiredMixin
from django.contrib.auth.models import User
from core.models import Student
from django.http import Http404, HttpResponseForbidden
from django.forms.widgets import HiddenInput
### VIEWS ###
class CreateLookout(LoginRequiredMixin, CreateView):
# can only be viewed by the user who created the lookout!...
model = Lookout
form_class = LookoutForm
fields = ['isbn',]
context_object_name = 'lookout'
template_name = 'create_lookout.html'
login_url = '/'
def get_context_data(self, **kwargs):
context = super(CreateLookout, self).get_context_data(**kwargs)
def form_valid(self, form):
me = Student.objects.get(user=self.request.user)
form = LookoutForm(initial={'owner' : me})
form.instance.owner = me
return super(CreateLookout, self).form_valid(form)
form.fields['owner'].widget = HiddenInput()
def get_context_data(self, **kwargs):
context = super(CreateLookout, self).get_context_data(**kwargs)
form = LookoutForm()
context['my_form'] = form
return context
......@@ -37,7 +36,6 @@ class DetailLookout(LoginRequiredMixin, DetailView):
template_name = 'detail_lookout.html'
login_url = '/'
def get_context_data(self, **kwargs):
context = super(DetailLookout, self).get_context_data(**kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment