I am attempting to pre-fill out 2 fields in a form that are foreign keys. The user selects an Account (not the user model) to use and then is given a list (from django-tables2) of products. The user then selects a Product to create a Listing for. The form has fields for Product and Listing. I am able to prefill the Product field but cannot figure out how to pass the Account pk/slug to the ListingCreate view. I am able to pass the Account if I hard code it as below but it needs to be dynamic. Thanks in advance!
I should be able to pass the parameter in the URL but the link to the CreateView is in a django-tables2 row and parameters are passed as record.pk or record.slug. I have not been able to figure out how to pass 2 parameters in django-tables2. I think this is my main issue. maybe…
I’m not familiar with django-tables2, so I can’t address it’s requirements, but you can supply multiple parameters in the url template call: <a href="{% url 'listing_create_from_account' record.pk account.pk %}">
If there’s some reason why you can’t do this in your template, you could always generate the url in your view and pass the completed url to render through the context.