Guest User

Untitled

a guest
Oct 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. from django.db import models
  2. from django import forms
  3. from django.contrib.auth.models import AbstractUser
  4. from django.contrib.auth.models import User
  5. from django.db.models.signals import post_save
  6. from django.dispatch import receiver
  7.  
  8.  
  9. from modelcluster.fields import ParentalKey, ParentalManyToManyField
  10. from modelcluster.contrib.taggit import ClusterTaggableManager
  11.  
  12. from wagtail.wagtailadmin.forms import WagtailAdminPageForm
  13. from wagtail.wagtailcore.models import Page, Orderable
  14. from wagtail.wagtailcore.fields import RichTextField
  15. from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel
  16. from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel
  17. from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
  18. from wagtail.wagtailsnippets.models import register_snippet
  19. from wagtail.wagtailsearch import index
  20.  
  21. class AccountIndexPage(Page):
  22. intro = RichTextField(blank=True)
  23. content_panels = Page.content_panels + [
  24. FieldPanel('intro', classname="full")
  25. ]
  26.  
  27. class AccountPageForm(WagtailAdminPageForm):
  28. def clean(self):
  29. cleaned_data = super(AccountPageForm, self).clean()
  30. reps = cleaned_data['reps']
  31. print(reps.count())
  32. if reps.count() > 5:
  33. self.add_error('reps', 'too many reps')
  34.  
  35. return cleaned_data
  36.  
  37. class AccountPage(Page):
  38. name = models.CharField(max_length=250)
  39. reps = ParentalManyToManyField(User, blank=True)
  40. search_fields = Page.search_fields + [
  41. index.SearchField('name'),
  42. #index.SearchField('body')
  43. ]
  44. content_panels = Page.content_panels + [
  45. FieldPanel('name'),
  46. FieldPanel('reps', widget=forms.SelectMultiple),
  47.  
  48. InlinePanel('billing_statements', label="Billing Statements"),
  49. InlinePanel('energy_report', label="Energy Report"),
  50. ]
  51. base_form_class = AccountPageForm
Add Comment
Please, Sign In to add comment