title: Domain Driven Design Onion Architecture with Django Rest Framework
body: <p>I have been reading recently about Domain Driven Design (DDD), I like the concept and especially the idea of Onion architecture goes with it (<a href="https://www.youtube.com/watch?v=pL9XeNjy_z4" rel="noreferrer">https://www.youtube.com/watch?v=pL9XeNjy_z4</a>).</p>
  
  <p>I am quite curious to understand how such an architecture we can implement with Django Rest Framework or in other words <strong>can we do DDD with Django rest framework in Onion arch style?</strong> </p>
  
  <ol>
  <li>Is it possible to map the concepts in Onion architecture to DRF?</li>
  <li>As frameworks like Apache isis (<a href="https://isis.apache.org/" rel="noreferrer">https://isis.apache.org/</a>) do DDD by building Object Oriented UIs where users can directly interact with domain entities, how DRF can possibly do such things?  </li>
  </ol>
  
  <p>As an example I have writing DRF Code in following fashion:</p>
  
  <p>In models.py I would have my models defined:</p>
  
  <pre><code>class Library(models.Model):
      library_id = models.AutoField(primary_key=True)
      name = models.CharField(max_length=30)
      ...
  
      #This helps to print in admin interface
      def __str__(self):
          return u"%s" % (self.name)
  </code></pre>
  
  <p>In serializers.py I would have my model serializers:</p>
  
  <pre><code>class LibrarySerializer(serializers.ModelSerializer):
      class Meta:
          model = Library
          fields = '__all__'
  </code></pre>
  
  <p>I will have corresponding url in urls.py:</p>
  
  <pre><code>router.register(r'libraries', LibraryViewSet)
  </code></pre>
  
  <p>and in views.py performing CRUD operations:</p>
  
  <pre><code>class LibraryViewSet(viewsets.ModelViewSet):
      queryset = Library.objects.all()
      serializer_class = LibrarySerializer
  </code></pre>
  
  <p>How would that relate to (perhaps with appropriate modifications) to DDD/Onion architecture?</p>