tags:

views:

27

answers:

1

Django forms split based on model type

    models.py

    TYPE = (
        ('general', 'General'),
        ('category2', 'Category2'),  
    )

    class Test(models.Model):
        type = models.CharField(max_length=765, choices=TYPE)


    forms.py

    class TestForm(ModelForm):

        class Meta:
            model = Test

Is it possible to split the form based on "type", make 2 separate forms based on model type

    TestFormGeneral
    TestFormCategory2

Update

    models.py

    class TestImport(models.Model):
        tests = models.ForeignKey(Test))

The above model pull out all the entries in forms, would like to restrict them based on type, rather than displaying the entire contents.

A: 

I think you are just looking for the right QuerySet.

To filter TestImport based on Tests type you can do like this:

TestsImport.objects.filter(tests__type__exact='General'

Not sure if thats what you want tho

will.i.am