My project is laid out like so:
1. page
has many: categories
2. category
belongs to: page
has many: items
3. item
belongs to: category
So, the way to do this is to exclude it from the form completely and set it in the view on save.
class ItemForm(forms.ModelForm):
class Meta:
model = Item
exclude = ('category',)
and the view:
def create_item(request, category_id):
if request.method == 'POST':
form = ItemForm(request.POST)
if form.is_valid():
item = form.save(commit=False)
item.category_id = category_id
item.save()
return redirect(...)
...etc...
which is served via a url:
url(r'^create_item/(?P\d+)/$, 'create_item', name='create_item'),
and which you can therefore link to from your categories list:
{% for category in categories %}
- {{ category.name }} - Create item
{% endfor %}