django rest framework multiple url arguments
<p>In rest api view I need to have 2 objects. For example:</p>

<pre><code>class Foo(models.Model):
    ....

class Bar(models.Model):
    ....
</code></pre>

<p>What is correct way to get them? I mean how should I configure urls? I think this is not really good practice: <code>url(r'^foo/(?P&lt;pk&gt;\d+)/bar/(?P&lt;pk&gt;\d+)/$', FooBarView.as_view())</code>
Or: <code>url(r'^foobar/$', FooBarView.as_view())</code> and then pass parameters: <code>?foo=1&amp;bar=2</code>.</p>

<p>I think it is more like a design problem.</p>

<p>Which one is better? I will say it depends on what is the relationship between model foo and model bar.</p>

<p>If you get model <strong>Class</strong> and model <strong>student</strong>, and you want to get student info and base on which class and relative student_number, like each class will have a student no.1. </p>

<p>you can go:</p>

<pre><code>url(r'^class/(?P&lt;class_pk&gt;\d+)/student/(?P&lt;student_pk&gt;\d+)/$')
</code></pre>

<p>If you want to get both model information, but you want put them into a statistic table,</p>

<p>you can go:</p>

<pre><code>url(r'^statistic/$')
</code></pre>

<p>then pass parameters like:</p>

<pre><code> ?class=1&amp;student=2
</code></pre>

<p>These are just simple examples, there should be other cases, and you should use other way to design your URL API.</p>

python django django-rest-framework