title: Django: How to custom save a model/form based on a non-persistent field of a form?
body: <p>I'm reposting this question since I asked 2 in 1 in a previous post.</p>
  
  <p>I want to set the field <strong><em>publication_date</em></strong> in the Entry model to change when the boolean <strong><em>to_publish</em></strong> is set to true, something like the custom save() method in the model, but I haven't been able to do that on the form.</p>
  
  <pre><code>#blog/models.py
  class Entry(models.Model):
      title = models.CharField(max_length=100)
      body = models.TextField()
      slug = models.SlugField(max_length=100, unique=True)
      creation_date = models.DateTimeField(editable=False)
      publication_date = models.DateTimeField(editable=False, null=True)
      modification_date = models.DateTimeField(editable=False)
  
      author = models.ForeignKey(User)
      categories = models.ManyToManyField(Category)
      tags = models.ManyToManyField(Tag)
  
      objects = EntryQuerySet.as_manager()
  
      def __str__(self):
          return self.title
  
      def was_published_recently(self):
          now = datetime.datetime.now()
          return now - datetime.timedelta(days=1) &lt;= self.publication_date &lt;= now
  
      def is_published(self):
          return self.publication_date is not False
  
      is_published.boolean = True
      is_published.short_description = 'Is it Published?'
  
      def get_absolute_url(self):
          return reverse("entry_detail", kwargs={"slug": self.slug})
  
      class Meta():
          verbose_name = "Blog Entry"
          verbose_name_plural = "Blog Entries"
          ordering = ['-creation_date']
  
      def save(self, *args, **kwargs):
          """ On save, update timestamps """
          if not self.id:
              self.creation_date = datetime.datetime.now()
          self.modification_date = datetime.datetime.now()
          return super(Entry, self).save(*args, **kwargs)
  
  #blog/forms.py
  class EntryAdminForm(forms.ModelForm):
      to_publish = forms.BooleanField(required=False)
  
      class Meta:
          model = Entry
          fields = ['title', 'body', 'slug', 'author', 'categories', 'tags']
  
  #blog/admin.py
  class EntryAdmin(MarkdownModelAdmin):
      form = EntryAdminForm
      list_display = ("title", "author", "creation_date", "publication_date", "is_published")
      prepopulated_fields = {"slug": ("title",)}
      formfield_overrides = {TextField: {'widget': AdminMarkdownWidget}}
  </code></pre>
  
  <p>Thank you.</p>