I have implemented this by looping through the form fields in a generic form
creation function.  Not sure if it is the 'proper way' but it works very
well for me.
-richard



On 6/5/08, Wim Feijen <[EMAIL PROTECTED]> wrote:
>
>
> Hi Richard and Rishabh,
>
> Thanks for your help.
>
> Actually, I want all fields to show up as a textarea with 40
> columns. :}  So I guess I just have to define each field separately
> without using inheritance. Which is a pity. It's a solution, though.
>
> Bye,
>
> Wim
>
>
> On 4 jun, 17:50, "Rishabh Manocha" <[EMAIL PROTECTED]> wrote:
> > What you want to do is perfectly doable. If (for example) you want the
> > street field to show up as a textarea with 40 columns in your form, you
> > would put something like this in your forms.py:
> >
> > class PersonForm(ModelForm):
> >    street = forms.CharField(widget = forms.TextArea(attrs = {"cols":40}))
> >    class Meta:
> >        model = Person
> >        fields = ['name', 'notes', 'email', 'cellphone',
> > 'officephone', 'skypename', 'street', 'number', 'suffix', 'zip',
> > 'city', 'country', 'photo']
> >
> > You can of-course do this with any field and use any widget for said
> field.
> >
> > Best,
> >
> > R
> >
> > On Wed, Jun 4, 2008 at 6:49 PM, Wim Feijen <[EMAIL PROTECTED]> wrote:
> >
> > > Hello people,
> >
> > > Being able to work with Django is very helpful to me. However, I am
> > > unsure whether I can create a form out of a database model and then
> > > customize that form. Using widgets to increase the textarea to 40
> > > would be great! But after reading  the documentation I am convinced I
> > > cannot do that.
> >
> > > One solution I can think of, is to loop over the fields in the form
> > > and start changing those? Is that possible? Then again, is that the
> > > proper way to do it?
> >
> > > My models are below.
> >
> > > Thanks for any help!
> >
> > > Wim
> >
> > > ----
> >
> > > class Person(models.Model):
> > >    name = models.CharField(max_length=100)
> > >    notes = models.CharField(max_length=100, blank=True)
> > >    email = models.EmailField(max_length=100, blank=True)
> > >    cellphone = models.CharField(max_length=100, blank=True)
> > >    officephone = models.CharField(max_length=100, blank=True)
> > >    chat = models.CharField(max_length=100, blank=True)
> > >    skypename = models.CharField(max_length=100, blank=True)
> > >    street = models.CharField(max_length=100, blank=True)
> > >    number = models.CharField(max_length=100, blank=True)
> > >    suffix = models.CharField(max_length=100, blank=True)
> > >    zip = models.CharField(max_length=100, blank=True)
> > >    city = models.CharField(max_length=100, blank=True)
> > >    country = models.CharField(max_length=100, blank=True)
> > >    photo = models.ImageField(upload_to='.', blank=True)
> > >    company = models.ManyToManyField(Company)
> > >    groups = models.ManyToManyField(Group)
> > >    deleted = models.BooleanField(default=False)
> > >    shared = models.ManyToManyField(User, related_name='shared')
> > >    owner = models.ForeignKey(User)
> >
> > >    def __str__(self):
> > >        return self.name
> >
> > > class PersonForm(ModelForm):
> > >    class Meta:
> > >        model = Person
> > >        fields = ['name', 'notes', 'email', 'cellphone',
> > > 'officephone', 'skypename', 'street', 'number', 'suffix', 'zip',
> > > 'city', 'country', 'photo']
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to