Django model how to add a ManyToManyField on save if condition not reach -
i have model article contain boolean field.
when add new article, if bool true, want country (which manytomayfield) bet set specific one.
the bool:
global_regions = models.booleanfield('global', default=true)
the manytomany:
article_country = models.manytomanyfield(country, verbose_name=_('country of article'), blank=true, null=true, related_name='country_press_article')
i tried :
def save(self, *args, **kwargs): if (self.article_url[:4] != "http") , (self.article_url[:5] != "https"): self.article_url = "https://" + self.article_url if not self.slug: self.slug = slugify(self.title) if self.global_regions == true: #here condition self.article_country.add(country.objects.get(id=257)) super(article, self).save(*args, **kwargs)
but, expecting, doesn't work.
what should if want work ?
Comments
Post a Comment