Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your template, define your link as follows.</p> <pre><code>{%url somename relevant_slug_text%} </code></pre> <p>Or :</p> <pre><code>href='/mysite.com/city/{{slug_text}}/venue/add' </code></pre> <p>In your url conf, define your url like:</p> <pre><code>url(r^'mysite.com/city/(?P&lt;slug_text&gt;\w+)/venue/add$', 'func_name', name='somename') </code></pre> <p>So, you can pass the value of relelvant_slug_text variable to your url as slug_text, and in your function definiton:</p> <pre><code>def func_name(request, slug_text): </code></pre> <p>So , you can pass text value to your funcrtion with slug_text parameter...</p> <p>EDIT: There are tow ways...</p> <p>One:</p> <p>Crete your city selection form using ModelForm..., then inthe second step, use posted data to populate your form again like:</p> <pre><code>form = StoreForm(request.POST) </code></pre> <p>then you can render this form to your template...</p> <p>But if it is not possible o use this, yo ucan do the following...</p> <p>Since you are using ModelForm to create your forms:</p> <pre><code>class StoreForm(forms.ModelForm): # your form field definitions are here </code></pre> <p>im your function, just override city field, but at this point, since you use modelform, your form thml will be created as </p> <pre><code>&lt;select&gt; &lt;option value="id of record"&gt;"unicode value of record"&lt;/option&gt; </code></pre> <p>So, you have record id's as option values. And you have slug_field values to initialize your field. So you have to get related city to use it...</p> <pre><code>my_city = City.objects.get(slug=&lt;your_slug_value&gt;) </code></pre> <p>Now you can override the form, but you must do it before you pass your form to a variable to render to your template...</p> <pre><code>StoreForm.base_fields['city'] = forms.ModelChoiceField(queryset=City.objects.all(), initial=my_city) form = StoreForm() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload