#models.py
#categorie model
class categorie(models.Model):
label_categorie=models.CharField(max_length=100)
lab_cat_date_posted=models.DateField(auto_now_add=True)
author=models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.label_categorie
def get_absolute_url(self):
return reverse('manageCat')
#categorie child model
class categorie_child(models.Model):
label_categorie_fille=models.CharField(max_length=100)
catF_date_posted=models.DateField(auto_now_add=True)
label_categorie=models.ForeignKey(categorie,on_delete=models.CASCADE,related_name='catF')
author=models.ForeignKey(User,on_delete=models.CASCADE)
def __str__(self):
return self.label_categorie_fille
def get_absolute_url(self):
return reverse('manage_categorie_child',kwargs={'pk': self.pk})
#urls.py
path('ManageCategorieChild/<int:pk>', ManageCategorieChild.as_view(), name='manage_categorie_child'),
path('UpdateCategorieChild/<int:pk>/edit',edit_categorie_child.as_view(),name='edit-categorie-child'),
#views.py
#current view (list of categorie child)
class ManageCategorieChild(DetailView):
model=categorie
template_name='store/managementCategorieChild.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
pub=categorie.objects.all()
context['catF'] = pub
return context
#updating view
class edit_categorie_child(SuccessMessageMixin,UpdateView):
model=categorie_child
template_name='store/update-catego rieChild.html'
fields=['label_categorie_fille',]
success_message='categorie fille updated successfully'
I don’t think I understand what you’re asking here
You want edit_categorie_child
to redirect to what URL on a successful post?
If it’s the url named manage_categorie_child
, then you can call reverse on that name, passing the label_categorie_id
field as the parameter.
(If this is not what you’re looking to do, please provide more details about the situation.)