Disclaimer: i am new to python but have drupal programming experience
I am reading the Definitive Guide to Django (http://www.djangobook.com/en/1.0/chapter07/). After issuing
python manage.py startapp books
python creates the books package with views.py inside. Later in the tutorial, we enter the following into that views.py file:
# Create your forms here.
from django import forms
from django.forms import form_for_model
from models import Publisher
PublisherForm = forms.form_for_model(Publisher)
TOPIC_CHOICES = (
('general', 'General enquiry'),
('bug', 'Bug report'),
('suggestion', 'Suggestion'),
)
class ContactForm(forms.Form):
topic = forms.ChoiceField(choices=TOPIC_CHOICES)
message = forms.CharField(widget=forms.Textarea())
sender = forms.EmailField(required=False)
def clean_message(self):
message = self.cleaned_data.get('message', '')
num_words = len(message.split())
if num_words < 4:
raise forms.ValidationError("Not enough words!")
return
Unless I typed something wrong or misunderstood something (either is likely), we now (seemingly) have a collision between forms (books/forms.py) and django forms. So, which does Python refer to above in
message = forms.CharField(widget=forms.Textarea())
This statement:
Really only pulls the name
form_for_modelinto the module-global namespace, the already existing nameformsis not affected. Even this:would not be a problem, because it only makes the name available in its fully-qualified form,
django.forms(which is unambigios and does not collide withforms).