1๐
As far I can see from your context: the language model (If even needed) should go to the developer because the developer is the one who closely relates to language, and will mostly consume it in views, and serializer, etc.
In general, we follow these three basic rules
- Keep apps small Each app
- Does one thing well
- Keep apps separate so they can be exported and used elsewhere
Just keep these simple basic rules in front of yourself whenever defining a new model in a Django app.
๐คUmar Hayat
0๐
If there are some fields common in every model in every app then we can use the following way to implement them:
from django.db import models
from django.conf import settings
import uuid
# Create your models here.
class BaseModel(models.Model):
class Meta:
abstract = True
id = models.UUIDField(default=uuid.uuid4, editable=False)
inactive = models.BooleanField(default=False, null=True, blank=False)
deleted = models.BooleanField(default=False, null=True, blank=False)
created_at = models.DateField(auto_now_add=True)
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, db_index=True, editable=False,
on_delete=models.SET_NULL, related_name="%(class)s_created")
updated_at = models.DateField(auto_now=True)
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, db_index=True, editable=False,
on_delete=models.SET_NULL, related_name="%(class)s_updated")
So, Now we can make new model by inheriting the BaseModel
like blew:
class Product(BaseModel):
"""
Product Model: Represents a product with features and details.
"""
name = models.CharField(max_length=120, help_text='Product name')
""" The rest of the fields will be the same as you have
"""
This way can design your models in your Django
based project.
- [Answered ]-Trying to include django form in my base.html, but not rendering in other templates?
- [Answered ]-Pre-registering users in database with python-social-auth
- [Answered ]-Reverse lazy error NoReverseMatch at django DeleteView
Source:stackexchange.com