0

I have my UpdateView for updating some of my data.

class WpisUpdate(UpdateView):
model=ProdukcjaStanTb
fields=[
        'temat',
        'podtemat',
        'proc_wym',
        'proc_auto',
        'proc_palnik',
        'proc_uruch',
        'proc_pakowanie',
        ]

Now, in my template I'd like to have only :

'proc_wym',
'proc_auto
'proc_palnik',
'proc_uruch',
'proc_pakowanie',

Fields, but also have access to fields "temat" and "podtemat" (to make big titles or web page title for example). In template i'm using {{form.temat.value}} tags, which are ok, but requires those fields in field list in UpdateView. I don't want user to change that. Is there any quick way to have those fields hidden in form but accessible while using easy:

{{ form.as_p }}

in template ? Or do i have to manually edit my form and add some html attributes, like read-only or input type="hidden" ?

Jakub
  • 193
  • 1
  • 10
  • 1
    Advise - don't use CBV if you (have no idea how it works :D ) are novice in Django. Or at least you need reed in the docs all about it and it's ancestors https://docs.djangoproject.com/en/1.8/ref/class-based-views/generic-editing/#updateview – madzohan Jun 28 '15 at 08:32

1 Answers1

2

Since this view only updates object you can always exclude unnecessary fields from autogenerated modelform - simply del them from your fields declaration then access 'temat', 'podtemat' in your template using object

template

{{ object.temat }} {{ object.podtemat }} {{ form.as_p }}

view

class WpisUpdate(UpdateView):
    model = ProdukcjaStanTb
    fields=[
        'proc_wym',
        'proc_auto',
        'proc_palnik',
        'proc_uruch',
        'proc_pakowanie',
    ]
madzohan
  • 11,488
  • 9
  • 40
  • 67