forms.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. """ catalog forms """
  2. from django.forms import ModelForm, fields, Textarea, TextInput, SelectMultiple
  3. from catalog.models import Book, Map, Movie, Person, Subscription, ZipCode
  4. class BookForm(ModelForm):
  5. long_description = fields.TextInput(attrs={"class": "test"})
  6. def __init__(self, *args, **kwargs):
  7. super(BookForm, self).__init__(*args, **kwargs)
  8. self.fields["authors"].queryset = Person.objects.active()
  9. class Meta:
  10. # need to do it this way to get the order of the fields we want.
  11. fields = (
  12. "title",
  13. "subtitle",
  14. "long_description",
  15. "synopsis",
  16. "image",
  17. "price",
  18. "shipping_cost",
  19. "shipping_cost_multiple",
  20. "sku",
  21. "featured",
  22. "tax_free",
  23. "authors",
  24. "editors",
  25. "illustrator",
  26. "publisher",
  27. "printer",
  28. "publish_date",
  29. "edition",
  30. "features",
  31. "dimensions",
  32. "pages",
  33. "isbn",
  34. "library_of_congress_number",
  35. "genre",
  36. )
  37. model = Book
  38. widgets = {
  39. "title": TextInput(attrs={"class": "input-xxlarge span7"}),
  40. "long_description": Textarea(attrs={"class": "input-xxlarge span7"}),
  41. "synopsis": Textarea(attrs={"class": "input-xxlarge span7", "rows": 3}),
  42. "subtitle": TextInput(attrs={"class": "input-xxlarge span7"}),
  43. "editors": TextInput(attrs={"class": "input-xxlarge span7"}),
  44. "features": TextInput(attrs={"class": "input-xxlarge span7"}),
  45. "authors": SelectMultiple(attrs={"class": "input-xlarge span5"}),
  46. }
  47. class MapForm(ModelForm):
  48. class Meta:
  49. exclude = (
  50. "created",
  51. "created_by",
  52. "last_updated",
  53. "last_updated_by",
  54. "subclass_type",
  55. "deleted",
  56. )
  57. model = Map
  58. widgets = {
  59. "title": TextInput(attrs={"class": "input-xxlarge span7"}),
  60. "long_description": Textarea(attrs={"class": "input-xxlarge span7"}),
  61. "synopsis": Textarea(attrs={"class": "input-xxlarge span7", "rows": 3}),
  62. }
  63. class MovieForm(ModelForm):
  64. class Meta:
  65. exclude = (
  66. "created",
  67. "created_by",
  68. "last_updated",
  69. "last_updated_by",
  70. "subclass_type",
  71. "deleted",
  72. )
  73. model = Movie
  74. widgets = {
  75. "title": TextInput(attrs={"class": "input-xxlarge span7"}),
  76. "long_description": Textarea(attrs={"class": "input-xxlarge span7"}),
  77. "synopsis": Textarea(attrs={"class": "input-xxlarge span7", "rows": 3}),
  78. "music": Textarea(attrs={"class": "input-xxlarge span7", "rows": 2}),
  79. }
  80. class SubscriptionForm(ModelForm):
  81. class Meta:
  82. exclude = (
  83. "created",
  84. "created_by",
  85. "last_updated",
  86. "last_updated_by",
  87. "subclass_type",
  88. "deleted",
  89. )
  90. model = Subscription
  91. widgets = {
  92. "title": TextInput(attrs={"class": "input-xxlarge span7"}),
  93. "long_description": Textarea(attrs={"class": "input-xxlarge span7"}),
  94. "synopsis": Textarea(attrs={"class": "input-xxlarge span7", "rows": 3}),
  95. }
  96. class PostalCodeForm(ModelForm):
  97. class Meta:
  98. exclude = (
  99. "created",
  100. "created_by",
  101. "last_updated",
  102. "last_updated_by",
  103. "subclass_type",
  104. "deleted",
  105. )
  106. model = ZipCode
  107. class PersonForm(ModelForm):
  108. class Meta:
  109. exclude = (
  110. "created",
  111. "created_by",
  112. "last_updated",
  113. "last_updated_by",
  114. "subclass_type",
  115. "deleted",
  116. "slug",
  117. )
  118. model = Person
  119. widgets = {
  120. "name": TextInput(attrs={"class": "input-xxlarge span7"}),
  121. "description": Textarea(attrs={"class": "input-xxlarge span7"}),
  122. "title": TextInput(attrs={"class": "input-xxlarge span7"}),
  123. }