开发者

Django forms split based on model type

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开发者_StackOverflow the entire contents.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜