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 ): ...@@ -16,7 +16,6 @@ class LookoutForm( forms.ModelForm ):
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset("", Fieldset("",
'owner',
Field('isbn', placeholder='0801884039'), Field('isbn', placeholder='0801884039'),
HTML("""<hr/ >"""), HTML("""<hr/ >"""),
FormActions( FormActions(
...@@ -30,5 +29,4 @@ class LookoutForm( forms.ModelForm ): ...@@ -30,5 +29,4 @@ class LookoutForm( forms.ModelForm ):
class Meta: class Meta:
model = Lookout model = Lookout
include = ('owner', 'isbn',)
...@@ -7,26 +7,25 @@ from braces.views import LoginRequiredMixin ...@@ -7,26 +7,25 @@ from braces.views import LoginRequiredMixin
from django.contrib.auth.models import User from django.contrib.auth.models import User
from core.models import Student from core.models import Student
from django.http import Http404, HttpResponseForbidden from django.http import Http404, HttpResponseForbidden
from django.forms.widgets import HiddenInput
### VIEWS ### ### VIEWS ###
class CreateLookout(LoginRequiredMixin, CreateView): class CreateLookout(LoginRequiredMixin, CreateView):
# can only be viewed by the user who created the lookout!...
model = Lookout model = Lookout
form_class = LookoutForm fields = ['isbn',]
context_object_name = 'lookout' context_object_name = 'lookout'
template_name = 'create_lookout.html' template_name = 'create_lookout.html'
login_url = '/' login_url = '/'
def get_context_data(self, **kwargs): def form_valid(self, form):
context = super(CreateLookout, self).get_context_data(**kwargs)
me = Student.objects.get(user=self.request.user) 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 context['my_form'] = form
return context return context
...@@ -37,7 +36,6 @@ class DetailLookout(LoginRequiredMixin, DetailView): ...@@ -37,7 +36,6 @@ class DetailLookout(LoginRequiredMixin, DetailView):
template_name = 'detail_lookout.html' template_name = 'detail_lookout.html'
login_url = '/' login_url = '/'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(DetailLookout, self).get_context_data(**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