Hello I am trying to pass a value from a link into CreateView and use that 
value as an inital value in a form.  I am not having much success and am 
not sure that I am doing this correctly.  Here is what I have so far:
Link:
<a href="/viewlit/addXC/{{ record.pk }}" target="blank" class="edit-item" 
title="Add"><img src="{% static "images/plus.png" %}" alt="Add" title="Add" 
style="width: 4%;"></a>Circuit Ref: {{ record.id1 }}<br>

urls.py
path('addXC/<path:circuitref>/', views.addXC.as_view(), name='addXC'),

views.py
class addXC(CreateView):
    model = Xcinventorytable
    fields = ['circuitref', 'circuitid', 'vendor', 'legacy', 'address', 
'city', 'state', 'ciopsticket', 'notes']
    success_url="/thanks/xcadded/"


    def get_form_kwargs(self):
        kwargs=super(addXC, self).get_form_kwargs()
        kwargs.update({'circuitref': circuitref})
        return kwargs

forms.py
class XcinventorytableForm(ModelForm):
    class Meta:
        model = Xcinventorytable
        widgets = {'notes': forms.TextInput(attrs={'size':200, 'rows':2})}
        help_texts = {'Circuitref': ('Enter the circuitref listed at the 
top of the last screen')}
        fields = '__all__'


    def __init__(self, *args, **kwargs):
        circuitref = kwargs.pop('circuitref')
        super(XcinventoryForm, self).__init__(*args, **kwargs)
        self.fields['circuitref'].initial = circuitref


Any help or suggestions are appreciated

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd729e92-6256-4c3a-84df-79250794d6f6%40googlegroups.com.

Reply via email to