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)

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.

I was thinking I should try

CouplingFormSet=modelformset_factory(Coupling)

and somehow subclass CouplingFormSet or pass some arguments to the
formset factory method, but I can't find any docs on how to  replicate
the above functionality (I can see that I can limit the queryset for
the Couplings, but not for the attributes, like couplingType).

How does one get to the fields of the underlying forms in a formset?

I've had a nosy at the django code, but reckon I'd be days
understanding it enough to work this out.

Has anyone done anything like this that could give me some advice, or
point me to a prevoius discussion on something like this?

Thanks in advance,
Bryan

--~--~---------~--~----~------------~-------~--~----~
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