On Tue, 2009-08-04 at 14:30 -0700, bnl wrote:
> Hi Folks
> 
> I'm trying to move up from a complex form based on a model declaration
> to a model formset built on the same idea.
> 
> I have a model which has some stuff that looks something like
> 
> class Vocab(models.Model):
>     ''' Holds the values of a choice list aka vocabulary '''
>     name=models.CharField(max_length=64)
> class Value(models.Model):
>     ''' Vocabulary Values '''
>     value=models.CharField(max_length=64)
>     vocab=models.ForeignKey(Vocab)
> class Coupling:
>     couplingType=model.ForeignKey(Vocab)
> class CouplingForm(form.modelForm):
>     class Meta:
>       model=Coupling
> class MyCouplingForm(CouplingForm):
>     def __init__(self,*args,**kwargs):
>         CouplingForm.__init__(self,*args,**kwargs)
>         vocab=Vocab.objects.get(name='couplingType')
>         self.fields['couplingType].queryset=Value.objects.filter
> (vocab=vocab)

Next time you're down at the store, you might want to pick up a few
blank lines to use in your email between the class definitions. The
above is very difficult to read.

> 
> It's a bit more complex than that (understatement, I hope I haven't
> mucked up the actuality in simplifying it), but I hope you get the
> picture ...
> 
> Anyway, that works fine ... but now I want to build a formset not just
> a form ...
> 
> Ideally, I want to apply the same logic to the formset that I do to
> the form (via subclassing). However, I can't quite work out how to do
> it.

This request doesn't necessarily make sense. A formset is not a form.
It's a set of forms. So *what* logic, specifically, are you trying to
apply here?

I'm really struggling to understand what you're trying to do, but maybe,
*maybe*, this will give you an idea about how you can customise the
forms in a formset and you can twist that your to your particular
preferences. It will at least show you some of the relevant methods to
examine:

http://www.pointy-stick.com/blog/2009/01/23/advanced-formset-usage-django/

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to