forms.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 = ('title', 'subtitle', 'long_description', 'synopsis',
  12. 'image', 'price', 'shipping_cost', 'shipping_cost_multiple',
  13. 'sku', 'featured', 'tax_free', 'authors', 'editors',
  14. 'illustrator', 'publisher', 'printer', 'publish_date',
  15. 'edition', 'features', 'dimensions', 'pages', 'isbn',
  16. 'library_of_congress_number', 'genre')
  17. model = Book
  18. widgets = {
  19. 'title': TextInput(attrs={
  20. 'class': 'input-xxlarge span7'}),
  21. 'long_description': Textarea(attrs={
  22. 'class': 'input-xxlarge span7'}),
  23. 'synopsis': Textarea(attrs={
  24. 'class': 'input-xxlarge span7',
  25. 'rows': 3}),
  26. 'subtitle': TextInput(attrs={
  27. 'class': 'input-xxlarge span7'}),
  28. 'editors': TextInput(attrs={
  29. 'class': 'input-xxlarge span7'}),
  30. 'features': TextInput(attrs={
  31. 'class': 'input-xxlarge span7'}),
  32. 'authors': SelectMultiple(attrs={
  33. 'class': 'input-xlarge span5'}),
  34. }
  35. class MapForm(ModelForm):
  36. class Meta:
  37. exclude = ('created', 'created_by', 'last_updated',
  38. 'last_updated_by', 'subclass_type', 'deleted')
  39. model = Map
  40. widgets = {
  41. 'title': TextInput(attrs={
  42. 'class': 'input-xxlarge span7'}),
  43. 'long_description': Textarea(attrs={
  44. 'class': 'input-xxlarge span7'}),
  45. 'synopsis': Textarea(attrs={
  46. 'class': 'input-xxlarge span7',
  47. 'rows': 3}),
  48. }
  49. class MovieForm(ModelForm):
  50. class Meta:
  51. exclude = ('created', 'created_by', 'last_updated',
  52. 'last_updated_by', 'subclass_type', 'deleted')
  53. model = Movie
  54. widgets = {
  55. 'title': TextInput(attrs={
  56. 'class': 'input-xxlarge span7'}),
  57. 'long_description': Textarea(attrs={
  58. 'class': 'input-xxlarge span7'}),
  59. 'synopsis': Textarea(attrs={
  60. 'class': 'input-xxlarge span7',
  61. 'rows': 3}),
  62. 'music': Textarea(attrs={
  63. 'class': 'input-xxlarge span7',
  64. 'rows': 2}),
  65. }
  66. class SubscriptionForm(ModelForm):
  67. class Meta:
  68. exclude = ('created', 'created_by', 'last_updated',
  69. 'last_updated_by', 'subclass_type', 'deleted')
  70. model = Subscription
  71. widgets = {
  72. 'title': TextInput(attrs={
  73. 'class': 'input-xxlarge span7'}),
  74. 'long_description': Textarea(attrs={
  75. 'class': 'input-xxlarge span7'}),
  76. 'synopsis': Textarea(attrs={
  77. 'class': 'input-xxlarge span7',
  78. 'rows': 3}),
  79. }
  80. class PostalCodeForm(ModelForm):
  81. class Meta:
  82. exclude = ('created', 'created_by', 'last_updated',
  83. 'last_updated_by', 'subclass_type', 'deleted')
  84. model = ZipCode
  85. class PersonForm(ModelForm):
  86. class Meta:
  87. exclude = ('created', 'created_by', 'last_updated',
  88. 'last_updated_by', 'subclass_type', 'deleted', 'slug')
  89. model = Person
  90. widgets = {
  91. 'name': TextInput(attrs={
  92. 'class': 'input-xxlarge span7'}),
  93. 'description': Textarea(attrs={
  94. 'class': 'input-xxlarge span7'}),
  95. 'title': TextInput(attrs={
  96. 'class': 'input-xxlarge span7'}),
  97. }