How to have a non-updating field on form

Is it possible to have a field on a Django form that does not either exist in the database, and/or update when the form is updated?

I tried something like this, examples of which were online, but those examples didn’t have Meta in the class:

class ItemFormBarcode(forms.ModelForm):
    category = forms.ChoiceField(choices=Item.category_displaychoices, widget=forms.RadioSelect)
    extra_field = forms.IntegerField()

    class Meta:
        model = Item
        fields = (
            'extra_field',
            'barcode',
            'category',
            'group',
            'title',
            'description',
            'price',
            'imgurl',
        )

If I put extra_field in the fields list I get the error:

django.core.exceptions.FieldError: Unknown field(s) (extra_field) specified for Item

If it is not in the fields list is obviously does not show.

My alternative at the moment is to fire a process after the save to remove the data in the field.

What makes you think this is true?

A ModelForm is an extension to a standard Form. The fields setting in Meta identifies which fields of a model are to be in included in the form. Other fields defined are part of the form, just like any other form.

Aye, ye be right. Thought I’m pretty sure I did it earlier and it wasn’t there…

Where you trying to display a form in the admin?

If you assign your form to the ModelAdmin class, it’ll show up there, too.

Not in admin, just in normal logged-in user view. Probably just a browser issue, or runserver did not restart, or luser error. :slight_smile: