Answer the question
In order to leave comments, you need to log in
How to generate a separate page for a model in django?
For example, there is a Product model that has a SlugField
How do I make it so that when a new instance of Product is created, the page /products/new_product_slug/ is generated? What to write in url'ah and so on?
Answer the question
In order to leave comments, you need to log in
First, override the save method on the model. So that when saving, a slug is created from something.
For this I use https://github.com/un33k/python-slugify
class Product(models.Model):
title = models.CharField(max_lenght=220)
slug = models.SlugField(unique=True, blank=True)
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Product, self).save(*args, **kwargs)
I guess something like:
where in <product_slug>
product -- the name of the model
slug -- the name of the SlugField of this model
Look -- this is , and in general read this lesson if you haven't already done so, everything is very well described there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question