Files
postgres-web/pgweb/news/forms.py
Jonathan S. Katz 2f52c4f7c4 Clean up whitespace in primary Python / HTML files
Clean up the whitespace in the primary Python / HTML files in
order to make it easier to apply changes going forward.
2017-11-29 08:21:35 -05:00

21 lines
732 B
Python

from django import forms
from django.forms import ValidationError
from pgweb.core.models import Organisation
from models import NewsArticle
class NewsArticleForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(NewsArticleForm, self).__init__(*args, **kwargs)
def filter_by_user(self, user):
self.fields['org'].queryset = Organisation.objects.filter(managers=user, approved=True)
def clean_date(self):
if self.instance.pk and self.instance.approved:
if self.cleaned_data['date'] != self.instance.date:
raise ValidationError("You cannot change the date on an article that has been approved")
return self.cleaned_data['date']
class Meta:
model = NewsArticle
exclude = ('submitter', 'approved', )