from django import forms
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _

from books.models import BookType
from egielda import settings


class BookForm(ModelForm):
    # Different max_length than in model (to allow dividers in ISBN number)
    isbn = forms.CharField(max_length=20, label=_("ISBN"))

    class Meta:
        model = BookType
        fields = ['isbn', 'publisher', 'title', 'publication_year', 'price']
        labels = {
            'isbn': _("ISBN"),
            'publisher': _("Publisher"),
            'title': _("Title"),
            'publication_year': _("Publication year"),
            'price': _("Price (%s)") % getattr(settings, 'CURRENCY', 'USD'),
        }
        widgets = {
            'isbn': forms.TextInput(attrs={'required': 'required'}),
            'publisher': forms.TextInput(attrs={'required': 'required'}),
            'title': forms.TextInput(attrs={'required': 'required'}),
            'publication_year': forms.NumberInput(attrs={'required': 'required', 'min': '1900', 'max': '2100'}),
            'price': forms.NumberInput(attrs={'required': 'required', 'max': '999.99'}),
        }

    def clean_isbn(self):
        data = self.cleaned_data['isbn']
        data = ''.join(filter(lambda x: x.isdigit(), data))
        return data
@@ -258,14 +258,12 @@
 ow d
-ivider
+ashe
 s in
@@ -271,15 +271,8 @@
 ISBN
- number
 )%0A  
@@ -326,16 +326,177 @@
 (%22ISBN%22)
+,%0A                           widget=forms.TextInput(%0A                               attrs=%7B'required': 'required', 'pattern': '%5B0-9-%5D+', 'title': 'ISBN number'%7D)
 )%0A%0A    c
@@ -631,39 +631,8 @@
 = %7B%0A
-            'isbn': _(%22ISBN%22),%0A
     
@@ -843,16 +843,16 @@
       %7D%0A
+
         
@@ -867,77 +867,8 @@
 = %7B%0A
-            'isbn': forms.TextInput(attrs=%7B'required': 'required'%7D),%0A
     

Improve ISBN field in Book Type form