title: Avoid redirection on model
body: <p>I'm fairly new in django and im building a simple web with 2 date pickers that are then used as a variable to ping the DB and populate a charfield with the result of the query.
  So far I've managed to render nicely the page and when the user submits the request, the query is triggered nicely and the value is fetched. The problem comes that after that, the model expects a url to redirect to but instead i want to stay on the same page and populate the result of the query into a charfield.
  So far this is what I got (I erased sensitive data):</p>
  <pre><code>from django.db import models
  from django.forms import ValidationError
  import psycopg2
  from django.utils import timezone
  
  
  class Event(models.Model):
      location = models.CharField(max_length=30, choices=[(&quot;us&quot;,&quot;US&quot;), (&quot;global&quot;,&quot;Global&quot;)])
      start = models.DateTimeField(default=timezone.now)
      end = models.DateTimeField(default=timezone.now)
      # This is the field I want to fill with the output of the query.
      result = models.CharField(max_length=20, default=0)
  
      # def get_absolute_url(self):
      # I have tried just comenting this but it throws and exception
      #     return bytes(str(self.pk), encoding='utf-8')
  
      def _do_insert(self, manager, using, fields, returning_fields, raw):
  
          query = &quot;&quot;&quot;
                  &quot;&quot;&quot;
          location_value = getattr(self, fields[0].name)
          start_date = getattr(self, fields[1].name)
          end_date = getattr(self, fields[2].name)
  
          if start_date &gt;= end_date:
              # How can I make this exception to be displayed as red under the dates?
              raise ValidationError(&quot;Start can't be later than end&quot;)
  
          start_date = start_date.strftime('%Y-%m-%d')
          end_date = end_date.strftime('%Y-%m-%d')
  
          res = self.fetch_data(query.format(start_date, end_date))
          # This is what I want to be displayed on the result box.
          return res[0]
  
      @staticmethod
      def fetch_data(query):
          # establishing the connection
          conn = psycopg2.connect(-----)
          cursor = conn.cursor()
          cursor.execute(query)
          result = cursor.fetchone();
          conn.close()
          return result
  </code></pre>
  <p>Any clues on how to achieve it?</p>
  <p>EDIT: I'm adding the view.py</p>
  <pre><code>class XDSoftDateTimePickerView(CreateView):
      model = Event
      form_class = XDSoftEventForm
      template_name = 'core/xdsoft_event_form.html'
  
  class HomeView(TemplateView):
      template_name = 'core/home.html'
  
  
  class EventDetailView(DetailView):
      model = Event
  </code></pre>
  <p>Template</p>
  <pre><code>&lt;form method=&quot;post&quot; autocomplete=&quot;off&quot; novalidate&gt;
      {% csrf_token %}
      {{ form|crispy }}
      &lt;button type=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;Submit&lt;/button&gt;
    &lt;/form&gt;
  </code></pre>
  <p>form.py</p>
  <pre><code>class DateForm(forms.Form):
      date = forms.DateTimeField(
          input_formats=['%d-%m-%Y'],
          widget=forms.DateTimeInput(attrs={
              'class': 'form-control datetimepicker-input',
              'data-target': '#datetimepicker1'
          })
      )
  
      def __init__(self, *args, **kwargs):
          super(DateForm, self).__init__(*args, **kwargs)
          self.fields['result'].widget.attrs['readonly'] = True
  </code></pre>