The simplest way I can think of is to override the model .save()
method and enforce your constraint there before calling the parent
class save method.
def save(self,*args,**kwargs):
if bool(self.arts_id) | bool(self.pics_id):
super(Post,self).save(*args,**kwargs)
else:
If any two inputs have the same name, both values are returned in a
list ala [request.POST.getlist('score')] With the checkboxes it's easy
to identify by value. I assume you might be able to figure out where
that score belongs by order, but I'm not sure order is guaranteed.
I think if it were me
Django is good for providing the backend, but most of your
functionality is probably going to be provided by ajax/javascript
which django will happily communicate with, but does not provide.
You might take a look at:
http://developer.yahoo.com/yui/examples/datatable/inlineediting.html
The problem appears to be because you are using a numeric key as field
name.
change this: field_id = t['id'] to field_id = str(t['id']) , or
use a real string as the name.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
As someone who jumped in as new to python, and django both. I'd say
you won't have much trouble, if you're comfortable with another
language. You can start out knowing nothing about it, but you'll need
some basics pretty quickly. Things about Python that I wish I'd
focused on before starting
from util import flatatt
My guess is that you really mean:
from django.newforms.util import flatatt
It works for the django widgets.py file because they are in the same
folder.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
Don't try too hard to directly link form to model.
For the attendance form, you might use a MultipleChoiceField
checkboxSelectMultiple widget, where the value of each choice is set
to the pk of the student model. You should get a list of id's that
were checked when the form gets submitted.
Why not do both. I've always preferred letting the database generate
an auto primary key (id in django) even if my usage is primarily a
different column for key. Storing an int isn't wasting much space,
what do you have to lose? I've got a users object for example that
requires a unique email
Sorry, first post had an error.
class CancelForm(forms.Form):
name = forms.CharField(label="name", max_length=10)
no = forms.CharField(label="personalid", max_length=10)
unit = forms.ChoiceField(label="unitname", choices=[])
def __init__(self,*args,**kwargs):
>From what I understand of Python, your choices code is only getting
called once when Python loads your form class for the first time. To
get around this you can assign choices from within the __init__() of
the form (which is called when the form is instantiated) This snippet
explains better
>From what I remember you do:
def myformcallback(f, **args):
exclude = ['author']
if f.name in exclude:
return None
return f.formfield(**args)
MyForm = form_for_instance(book, formfield_callback=myformcallback)
if request.POST:
form = MyForm(request.POST)
Malcolm,
I'm not the op, but have done what you suggested in splitting models
and linking with OnetoOne fields in the past. It worked perfectly
except for one problem: I couldn't figure out any way to order search
results by a field in a related model. I tried everything I could
think of and
In addition to what Kyle said I've also noticed I had to 'pop' custom
kwargs before passing to the super since it isn't expecting them.
try:
t = kwargs.pop('title')
except:
...
call super
... do stuff.
On Mar 27, 10:20 am, "Kyle Fox" <[EMAIL PROTECTED]> wrote:
> This is just a guess, but
I thought the same thing at first, and ended up making my own class
that bound the forms and models together (a little like
form_for_model, but handles multiple 1-1 models). I thought it would
save me a lot of time, but looking back I've only been able to use it
on a few forms. I think the
I don't know if it would be of any use to you, but when faced with
this problem I ended up making subclass of forms.Form that handled one
to one relations. It works a little like form_for_model/instance in
that it generates the form based on the model definition rather than
fields you define.
Maybe I'm misunderstanding ,but if you just need to validate why give
your form a custom clean() method to take the p_id parameter and
verify with self.clean_data?
If you have to pass it in on creation, this is what I did when I
extended extended the form class to handle a bunch of OneToOneField
You might take a look at BaseForm._html_output(). It's the function
that does most of the work for .as_p() and so on. Using it as a guide
you should be able to make your own render function to add to your
form class.
--~--~-~--~~~---~--~~
You received this
I had similar problems, trying to tie the form and model too closely.
>From what I understand the form needs to be aware of the model(s), but
there isn't anything forcing you to a 1:1 relationship (form_for_model
does that for convenience, but isn't the only way). You just have to
override
def CustomUser_callback(field, **kwargs):
display_fields = ('firstname', 'lastname', 'email', 'phone')
if field.name in display_fields:
return field.formfield(**kwargs)
else:
return None
After looking at the django source, I realized that the 'f' was for
field, not
Please forgive me if this is a stupid question, but I haven't been
able to find a good answer searching! Doesn't help that I'm only a
few weeks acquainted with both both Django and Python. I'm
definitely liking it so far.
Anyway, I've got a custom user model with several required foreign
20 matches
Mail list logo