forms - Autopopulate slug field without using third party app in django -


this model:

 class child(models.model):         child_name = models.charfield(max_length=150, null=true, blank=true)         slug = models.slugfield(max_length=150,null=true, blank=true)         # slug = autoslugfield(populate_from='child_name')         blood_group = models.charfield(max_length=5, blank=true)         startup = models.foreignkey(startup)      class meta:         verbose_name_plural = 'children'         unique_together = ('slug', 'startup')      def save(self, *args, **kwargs):               if self.id none:         self.slug = slugify(self.child_name)       else:         self.slug = slugify(self.child_name)       super(child, self).save(*args, **kwargs) 

but not auto-populate slug field in form. form :

class childform(slugcleanmixin,         forms.modelform):     class meta:         model = child         fields = '__all__'         widgets = {'startup': hiddeninput(),                      }  views.py:  class childcreate(newslinkgetobjectmixin,startupcontextmixin,    createview):     form_class = childform     model = child         def get_initial(self):         startup_slug = self.kwargs.get(             self.startup_slug_url_kwarg)         self.startup = get_object_or_404(             startup, slug__iexact=startup_slug)         initial = {             self.startup_context_object_name:                 self.startup,         }         initial.update(self.initial)         return initial 

how autopopulate slug field in form when typing child name. there way that? tried using django-autoslug not create unique slug , not maintain combined unique-together constraints.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -