Using ModelForm with ID associated with PostgreSQL Sequence

11 views
Skip to first unread message

Néstor Boscán

unread,
Oct 21, 2014, 12:24:14 AM10/21/14
to django...@googlegroups.com
Hi

I have an existing PostgreSQL database where all tables have sequences associated to their primary key and no, I can't change it.

When I create a ModelForm it generates "Required field" for the ID field because it doesn't have any data.

Any ideas how to manage this situation?

Regards,

Néstor

Collin Anderson

unread,
Oct 21, 2014, 11:46:57 AM10/21/14
to django...@googlegroups.com
Hi Néstor,

Are you using an AutoField()? It seems to me that _should_ work correctly. In any case setting editable=False should fix it.

Otherwise, would it work to put your primary key field in exclude?

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        exclude = ['id']

Collin

Reply all
Reply to author
Forward
0 new messages