Django Model Generator - Slash-separated fields
Project description
Django-MG 🔥
Created by Mobin Hasanghasemi
Email: mobin.hasanghasemi.m@gmail.com
Django Model Generator. Slash-separated fields. Zero config.
🚀 Quick Start
Step 1: Install
pip install django-mg
Step 2: Add to Django
settings.py:
INSTALLED_APPS = [
# Django apps
'django.contrib.admin',
'django.contrib.auth',
# ...
# Add this
'django_mg', # Django-MG
]
Step 3: Generate Model
python manage.py generate_model
Step 4: Follow Prompts
👋 Hi! Type 'generate.model' to start:
>>> generate.model
🚀 DJANGO-MG - MODEL GENERATOR
Created by Mobin Hasanghasemi
Email: mobin.hasanghasemi.m@gmail.com
======================================================================
📋 BASIC: 01=Name | 02=Title | 03=Slug
📝 CONTENT: 04=Rich | 05=Text | 06=Short
🖼️ MEDIA: 07=Image | 08=Gallery | 09=File
💰 ECOM: 10=Price | 11=Stock | 12=Active | 13=SKU
🔗 REL: 14=Category | 15=Tags | 16=Author
⏰ TIME: 17=Created | 18=Updated | 19=Published
⚙️ PRO: 20=Weight | 21=Dimensions | 22=Status | 23=Priority
🔍 SEO: 24=Meta | 25=Desc
📧 EXTRA: 26=URL | 27=Email | 28=Phone
======================================================================
💡 FORMAT: py filename.py ClassName 01/04/10/17
Example: py models.py Product 01/04/10/11/17
Means: Name + Rich + Price + Stock + Created
======================================================================
🎯 Enter your command:
>>> py models.py Product 01/10/11/17
🔨 Creating 'Product' with fields: 01/10/11/17
✅ Model 'Product' created! (4 fields)
📦 Install packages:
pip install django-money
✅ Generated fields:
• Name
• Price
• Stock
• Created
🚀 Next steps:
python manage.py makemigrations
python manage.py migrate
Step 5: Run Migrations
python manage.py makemigrations
python manage.py migrate
💡 Field Codes Guide
| Code | Field | Description | Package |
|---|---|---|---|
01 |
Name | CharField(max_length=255) |
- |
02 |
Title | CharField(max_length=200) |
- |
03 |
Slug | Auto-slug from name | django-autoslug |
04 |
Rich | RichTextField (CKEditor) | django-ckeditor |
05 |
Text | TextField() |
- |
06 |
Short | CharField(max_length=500) |
- |
07 |
Image | FilerImageField | django-filer |
08 |
Gallery | ManyToMany images | django-filer |
09 |
File | FilerFileField | django-filer |
10 |
Price | MoneyField (USD) | django-money |
11 |
Stock | PositiveIntegerField() |
- |
12 |
Active | BooleanField(default=True) |
- |
13 |
SKU | CharField(unique=True) |
- |
14 |
Category | ForeignKey to Category | - |
15 |
Tags | TaggableManager | django-taggit |
16 |
Author | ForeignKey to User | - |
17 |
Created | DateTimeField(auto_now_add=True) |
- |
18 |
Updated | DateTimeField(auto_now=True) |
- |
19 |
Published | DateTimeField(null=True) |
- |
20 |
Weight | DecimalField(kg) |
- |
21 |
Dimensions | CharField(max_length=50) |
- |
22 |
Status | Draft/Published/Archived | - |
23 |
Priority | PositiveSmallIntegerField() |
- |
24 |
Meta | Meta title (SEO) | - |
25 |
Desc | Meta description (SEO) | - |
26 |
URL | URLField() |
- |
27 |
EmailField() |
- | |
28 |
Phone | CharField(max_length=20) |
- |
💎 Real Examples
Product Model
py models.py Product 01/10/11/12/17
Fields: Name + Price + Stock + Active + Created
Blog Post
py blog/models.py Post 02/04/06/15/17/22
Fields: Title + Rich + Short + Tags + Created + Status
Image Gallery
py gallery/models.py Photo 01/07/08/17
Fields: Name + Image + Gallery + Created
Contact Form
py contact/models.py Contact 01/27/28/05/17
Fields: Name + Email + Phone + Text + Created
📦 Optional Features
Basic (No extras)
pip install django-mg
E-commerce
pip install "django-mg[money,filer]"
Content
pip install "django-mg[ckeditor,taggit]"
Full Features
pip install "django-mg[filer,money,ckeditor,taggit,autoslug]"
🛠️ Troubleshooting
"Unknown command: generate_model"
# settings.py
INSTALLED_APPS += ['django_mg'] # این خط رو اضافه کن
"Module not found"
pip install django-mg # دوباره نصب کن
"Invalid field code"
# فقط 01-28 استفاده کن
# مثال: py models.py User 01/27/17 (Name + Email + Created)
Dependencies
# pip requirements خودکار نشون میده
python manage.py generate_model
# 📦 Install packages:
# pip install django-money
📊 Generated Model Example
Command: py models.py Product 01/10/11/17
Output (models.py):
# Auto-generated: Product
# Generated: 2025-01-20 14:30:25
# Fields: name, price, stock, created
# Created by Mobin Hasanghasemi (mobin.hasanghasemi.m@gmail.com)
from django.db import models
from djmoney.models.fields import MoneyField
class Product(models.Model):
name = models.CharField(max_length=255)
price = MoneyField(max_digits=14, decimal_places=2, default_currency='USD')
stock = models.PositiveIntegerField(default=0)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
class Meta:
verbose_name = 'product'
verbose_name_plural = 'products'
🔗 Links
📄 License
MIT License - see LICENSE file.
© 2025 Mobin Hasanghasemi
📧 mobin.hasanghasemi.m@gmail.com
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_mg-1.0.1.tar.gz.
File metadata
- Download URL: django_mg-1.0.1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e9f11362040d411cc709404db2d2f83da6c60d7f867e3819cda00f99b13410
|
|
| MD5 |
cf44164090742eb1e180a566357288fd
|
|
| BLAKE2b-256 |
d28e8ddcab57eb69dbf2b3f7ab34eddaecba6b33efb0fbfa55166bbc937f461c
|
File details
Details for the file django_mg-1.0.1-py3-none-any.whl.
File metadata
- Download URL: django_mg-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb76e3147cdcbd01290cb10a86ca6d25e8bdcbcc15fed79b1b9f809970a8d71
|
|
| MD5 |
a575e7a984785a6d01b6ec898a678cf4
|
|
| BLAKE2b-256 |
2e16ceaa2b5b72d64b9bddcd3a1f564551263166daca756cef1f98eba1be5838
|