A model is your database blueprint - it defines how your data is structured and stored. It contains the essential fields and behaviors of the data you're storing. Generally, each model maps to a single database table.
Picking from Django Docs concerning model basics:
django.db.models.Model
.Let's face it: if you're new to Django, wrapping your head around model creation can take a while. You need to understand Python classes, inheriting from django.db.models.Model
, define fields as class attributes, and that's just the beginning! It's powerful, sure, but it can be overwhelming.
This is where djuix.io swoops in to save the day!
While Django's approach to models is powerful, it can be challenging for beginners. Let's compare the traditional Django approach with Djuix's streamlined method.
In standard Django, you define models as Python classes:
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=10, decimal_places=2)
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
This requires understanding of Python class syntax, Django's model API, and various field types.
Djuix eliminates the need to write Python code for model creation. Instead, you can use our intuitive GUI:
Note: To see the code structure of the created model click on the more icon and select “View”
Djuix supports native Django fields with an extended field to make creating realtionships intuiative and convinent. Here's a list of supported fields:
CharField IntegerField BooleanField BigIntegerField TextField DateField
ManyToManyField
DateTimeField EmailField FileField ImageField JSONField
OneToOneField
TimeField SlugField DecimalField FloatField PositiveIntegerField
ForeignKeyField
→ All these fields can be vetted with detailed information refer to the here
Djuix simplifies the process of creating relationships between models. When you select ForeignKey, OneToOneField, or ManyToManyField, Djuix will automatically provide a list of available models in your project, grouped by app.
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
related_name='profile'
)
bio = models.TextField()
Djuix introduces the AuthField, a custom field type designed to simplify the process of relating models to Django's built-in User model or your custom user model.
In traditional Django, you might write:
from django.contrib.auth.models import User
from django.db import models
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.TextField(blank=True)
With Djuix, you can achieve the same result by selecting "AuthField" and choosing the relationship type (OneToOne, ForeignKey, or ManyToMany) in the GUI.
This approach not only simplifies the code but also automatically handles the import of the correct User model, whether it's the default Django User or a custom user model.