擅长:python、mysql、java
<p>你可以有一家生产披萨的工厂:</p>
<pre><code>def pizzaform_factory(restaurant):
class PizzaForm(ModelForm):
class Meta:
model = Pizza
toppings = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple(),
queryset=restaurant.toppings.all()
)
return PizzaForm
</code></pre>
<p>并在您的视图中使用它:</p>
^{pr2}$
<p>也许限制你的模型,以确保你不能创造不可能的订单。{end}如果你仍然不能使用一个命令,就不能使用命令。在</p>