ModelChoiceField and initial value

2009-02-23 Thread Brandon Taylor
Hi everyone, What's the trick to getting a ModelChoiceField to use the first object in a QuerySet as the initial value to get rid of -? If I do: qs = Model.objects.all() my_field = forms.ModelChoiceField(queryset=qs, initial=qs[0]) I still get -- as the first choice. TIA, Bran

Re: ModelChoiceField and initial value

2009-02-23 Thread Brandon Taylor
Solved: ModelChoiceField(empty_label=None) On Feb 23, 9:14 pm, Brandon Taylor wrote: > Hi everyone, > > What's the trick to getting a ModelChoiceField to use the first object > in a QuerySet as the initial value to get rid of -? > > If I do: > qs = Model.objects.all() > my_field = forms.

how to show currently selected choices in ManyToMany fo

2009-02-23 Thread Margie
Let's say I have a model like this: class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) pulisher = models.ForeignKey(Publisher, blank=True, null=True) I want to generate a form that can be used to edit an existing Book object.

Re: Not understand help_text

2009-02-23 Thread Mark Jones
That is exactly the kind of WET I was talking about. as_p() with appropriate CSS styling will render really nice forms as is, with the exception of the help_text. I even think that could be fixed without any major rework, just a change in the as_p() string from def as_p(self): "Ret

Re: How to populate a custom ModelForm?

2009-02-23 Thread rajeesh
> I get "Item not found" when I go to that entry. > I don't know what happened. I'd checked the link many times yesterday. But 'not found' by today! Anyway, pasted once more to http://dpaste.com/hold/427/ . > That sounds like the normal use-case for Meta.exclude in the ModelForm. > Can you just

Re: Is safe unsafe?

2009-02-23 Thread Jacob Kaplan-Moss
On Mon, Feb 23, 2009 at 7:49 PM, Brian Neal wrote: > Interesting, I've also come across this: > > http://codespeak.net/lxml/lxmlhtml.html#cleaning-up-html > > I've heard it is very fast as it is just a python binding to a C- > library...? Short version: don't use lxml.html.clean, either. Long v

Re: How to populate a custom ModelForm?

2009-02-23 Thread rajeesh
Pasting the code here to check any further problem ;) ## I've a model like this: class Receipt(models.Model): r_number= models.IntegerField() transaction = models.OneToOneField(Transaction,editable=False) ## Transaction is from another app and there it is used as usua

Caching db connections

2009-02-23 Thread A B
I need to use a db backend (Sybase) which is not supported by Django. I don't need to use the Django ORM but would like Django to maintain a pool of open db connections so that I don't have to make a new connection every time I need to run a query (similar functionality offered by Apache::DBI in m

Re: how to show currently selected choices in ManyToMany fo

2009-02-23 Thread Margie
Ok - I think I should actually be using initial - but still haven't gotten that to actually work. I'm trying something like this: In models.py class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) pulisher = models.ForeignKey(P

<    1   2