Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django import forms
- from django.contrib.auth.models import AbstractUser
- from django.contrib.auth.models import User
- from django.db.models.signals import post_save
- from django.dispatch import receiver
- from modelcluster.fields import ParentalKey, ParentalManyToManyField
- from modelcluster.contrib.taggit import ClusterTaggableManager
- from wagtail.wagtailadmin.forms import WagtailAdminPageForm
- from wagtail.wagtailcore.models import Page, Orderable
- from wagtail.wagtailcore.fields import RichTextField
- from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel
- from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel
- from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
- from wagtail.wagtailsnippets.models import register_snippet
- from wagtail.wagtailsearch import index
- class AccountIndexPage(Page):
- intro = RichTextField(blank=True)
- content_panels = Page.content_panels + [
- FieldPanel('intro', classname="full")
- ]
- class AccountPageForm(WagtailAdminPageForm):
- def clean(self):
- cleaned_data = super(AccountPageForm, self).clean()
- reps = cleaned_data['reps']
- print(reps.count())
- if reps.count() > 5:
- self.add_error('reps', 'too many reps')
- return cleaned_data
- class AccountPage(Page):
- name = models.CharField(max_length=250)
- reps = ParentalManyToManyField(User, blank=True)
- search_fields = Page.search_fields + [
- index.SearchField('name'),
- #index.SearchField('body')
- ]
- content_panels = Page.content_panels + [
- FieldPanel('name'),
- FieldPanel('reps', widget=forms.SelectMultiple),
- InlinePanel('billing_statements', label="Billing Statements"),
- InlinePanel('energy_report', label="Energy Report"),
- ]
- base_form_class = AccountPageForm
Add Comment
Please, Sign In to add comment