title: Django model instance fields with ManyToMany relationship to Dict
body: <p>I'm trying to create a simple action that gets one record (with ManyToMany relationship) from the database then display the JSON serialized instance, here is how I did it for now:</p>
  
  <p>the service model:</p>
  
  <pre class="lang-py prettyprint-override"><code>class SystemService(models.Model):
      name = models.CharField(max_length=35, unique=True, null=False, blank=False)
      verion = models.CharField(max_length=35, unique=True, null=False, blank=False)
  
      def __str__(self):
          return self.name
  </code></pre>
  
  <p>the server model:</p>
  
  <pre class="lang-py prettyprint-override"><code>class Server(models.Model):
      name = models.CharField(max_length=35, unique=True, null=False, blank=False)
      ip_address = models.GenericIPAddressField(protocol='both', unpack_ipv4=True,
                                                null=False, blank=False, unique=True)
      operating_system = models.ForeignKey(OperatingSystem, null=False, blank=False)
      monitored_services = models.ManyToManyField(SystemService)
      info = models.CharField(max_length=250, null=True, blank=True)
      pause_monitoring = models.BooleanField(default=False)
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
      def __str__(self):
          return self.name
  </code></pre>
  
  <p>Here is how it is now using muj-gabriel answer:</p>
  
  <pre class="lang-py prettyprint-override"><code>def get_server(request, server_id):
      try:
          server_object = Server.objects.get(id=server_id)
          data = {
              'name': server_object.name,
              'ip_address': server_object.ip_address,
              'os': server_object.operating_system.name,
              'info': server_object.info,
              'monitoring_paused': server_object.pause_monitoring,
              'created_at': server_object.created_at,
              'update_at': server_object.updated_at,
              'services': {service['id']: service['name'] for service
                       in server_object.monitored_services.values('id', 'name')}
          }
          return JsonResponse(data)
      except Server.DoesNotExist:
          return JsonResponse({'error': 'Selected object does not exits!'})
  </code></pre>
  
  <p>I don't think that what I did is good enough since I have to repeat the same thing each time I need to get one instance as JSON, so I would like to know if is there a pythonic and dynamic way to do it?</p>