Re: Constraints to a model

2007-05-16 Thread dballanc
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:

Re: Using newforms for multiple db rows

2007-05-11 Thread dballanc
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

Re: CRUD - grid? Is Django suitable for this?

2007-05-10 Thread dballanc
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

Re: Validating dynamically generated forms

2007-05-10 Thread dballanc
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

Re: How well should I know Python before using Django?

2007-05-09 Thread dballanc
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

Re: Custom Widget

2007-05-08 Thread dballanc
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

Re: Using newforms for multiple db rows

2007-05-03 Thread dballanc
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.

Re: Database design question

2007-04-25 Thread dballanc
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

Re: cache problem of new forms: make ChoicesField's choices list on fly

2007-04-23 Thread dballanc
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):

Re: Choice newforms field not auto updating...

2007-04-13 Thread dballanc
>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

Re: newforms and form_from_instance

2007-04-03 Thread dballanc
>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)

Re: common model

2007-03-31 Thread dballanc
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

Re: DB Super Model (ahem)

2007-03-27 Thread dballanc
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

Re: Forms vs. Models: Redundant?

2007-03-27 Thread dballanc
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

Re: Multiple Forms and/or Models from one template (newforms)

2007-03-19 Thread dballanc
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.

Re: newb: newforms and passing an extra parameter: forms.SalesForm(request.POST, p_id)

2007-03-16 Thread dballanc
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

Re: newforms and templating

2007-03-14 Thread dballanc
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

Re: newforms - filling a custom form with data from a model instance

2007-03-06 Thread dballanc
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

Re: form_for_model and hidden foreign key?

2007-02-22 Thread dballanc
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

form_for_model and hidden foreign key?

2007-02-21 Thread dballanc
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