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
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.
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.
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
> 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
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
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
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
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
101 - 109 of 109 matches
Mail list logo