I was trying out forms and created a class and its form class MyCategory(models.Model): name=models.CharField(max_length=10) description=models.TextField(help_text='a description about the category') slug=models.SlugField(unique=True,help_text='will be auto generated from name')
class Meta: verbose_name_plural="MyCategories" def __unicode__(self): return self.name def get_absolute_url(self): return ('myapp_category_detail',(),{'slug':self.slug}) get_absolute_url=models.permalink(get_absolute_url) classMyCategoryForm(ModelForm): class Meta: model=MyCategory I set the slug to be auto generated in admin.py class MyCategoryAdmin(admin.ModelAdmin): prepopulated_fields= {'slug':['name']} ordering=['name'] After that I created an edit view for the class def edit_category(request,slug): cat=get_object_or_404(MyCategory,slug=slug) if request.method=='POST': form=MyCategoryForm(request.POST,instance=cat) if form.is_valid(): form.save() redirect('myapp_category_list') else: print 'edit_category::invalid form' form=MyCategoryForm(instance=cat) else: form=MyCategoryForm(instance=cat) return render_to_response('myapp/edit_category.html', {'categoryform':form}) In the edit_category.html I displayed the form as <form method='post' action='{% url edit_category categoryform.instance.slug %}' > <table> {{ categoryform.as_table }} </table> <input type='submit' name='Save' /> </form> When the template is rendered it shows the helptext which I provided in the model's slugfield.But unlike in the django admin 's edit page ,the slug is not auto generated when I type in a new name for the category. Similarly I tried an add category page.Here also the slug is not auto generated,even though the helptext says that it will be.I have enabled javascript for my browser.Do I have to write a javascript for each of these pages or can I use some script the admin uses? I am only getting familiar with the basics..so please bear with the newbish doubts thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.