Im a little confuse about Django responsibility architecture.
In my project, i chose work with CBV and built-in urls. In my studies, i understood that the responsibilities are divided into: Model, View, Template where:
Model takes care data and DataBase, from docs : "definitive source of information about your data. It contains the essential fields and behaviors of the data you’re storing"
View takes care about request and response
Template is a hight level layer app to show data
correct me if not that.
Most of my questions are where to put the codes, eg:
In my models i use something like:
class Product(models.Model):
..."""other fields"""
user = models.ForeignKey(User, on_delete=models.CASCADE)
product_title = models.CharField(max_length=255, default='product_title')
product_title_seo = models.CharField(max_length=255, default='product_title_seo')
slug = models.SlugField(max_length=250,unique=True,null=True)
def __str__(self):
return self.product_title
def get_absolute_url(self):
return reverse('product_change', kwargs={'slug': self.slug, 'pk': self.pk})
def save(self, *args, **kwargs):
self.product_title_seo = slugify(self.product_goal + " " + self.product_type + " " + self.product_district)
self.product_title = slugify(self.product_title)
if not self.slug:
self.slug = self.product_title_seo
return super().save(*args, **kwargs)
So as we can see i have 3 methods inside my model class, but i need some treatment for the majority of fields which would represent a considerable increase in methods.
This approach is correct, a lot of methods in model class, if not how separate and where put that methods?