Skip to main content

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
======================================================================
# List of available fields: 01-100 (see Field Codes Guide below)
======================================================================
💡 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/16/10/18

🔨 Creating 'Product' with fields: 01/16/10/18
✅ Model 'Product' created! (4 fields)

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 SlugField(unique=True)
04 UUID UUIDField(auto=True) django-extensions
05 AutoSlug Auto-slug from name django-autoslug
06 ShortUUID ShortUUIDField() shortuuidfield
07 Text TextField(blank=True, null=True)
08 ShortText CharField(max_length=500)
09 Integer IntegerField()
10 PosInt PositiveIntegerField()
11 SmallInt SmallIntegerField()
12 PosSmallInt PositiveSmallIntegerField()
13 BigInt BigIntegerField()
14 Decimal DecimalField(max_digits=12, decimal_places=2)
15 Float FloatField()
16 Money MoneyField(USD) django-money
17 Date DateField()
18 DateTime DateTimeField(auto_now_add=True)
19 Time TimeField()
20 Duration DurationField()
21 Monitor MonitorField(monitor='status') django-model-utils
22 AutoCreated AutoCreatedField() django-model-utils
23 AutoModified AutoLastModifiedField() django-model-utils
24 Boolean BooleanField(default=True)
25 NullBoolean BooleanField(null=True)
26 StatusField StatusField() django-model-utils
27 FSM FSMField(default='new') django-fsm
28 Email EmailField(blank=True, null=True)
29 URL URLField(blank=True, null=True)
30 IP Address GenericIPAddressField(blank=True, null=True)
31 Phone PhoneNumberField django-phonenumber-field
32 Country CountryField django-countries
33 Region RegionField django-countries-plus
34 File FileField(upload_to='files/')
35 Image ImageField(upload_to='images/')
36 Thumbnail ThumbnailerImageField easy-thumbnails
37 ProcessedImage ProcessedImageField django-imagekit
38 FilerFile FilerFileField django-filer
39 FilerImage FilerImageField django-filer
40 RichText RichTextField django-ckeditor
41 Quill QuillField django-quill-editor
42 Markdown MarkdownxField django-markdownx
43 Redactor RedactorField django-redactor
44 Tags TaggableManager django-taggit
45 Array ArrayField(CharField(100))
46 JSON JSONField
47 HStore HStoreField
48 PickledObject PickledObjectField django-picklefield
49 EncryptedChar EncryptedCharField django-encrypted-model-fields
50 EncryptedText EncryptedTextField django-encrypted-model-fields
51 O2O User OneToOneField(User)
52 FK User ForeignKey(User)
53 ForeignKey ForeignKey('OtherModel')
54 OneToOne OneToOneField('OtherModel')
55 ManyToMany ManyToManyField('OtherModel')
56 GenericFK GenericForeignKey()
57 GenericRelation GenericRelation('OtherModel')
58 Point PointField django.contrib.gis
59 Polygon PolygonField django.contrib.gis
60 LineString LineStringField django.contrib.gis
61 Country CountryField django-countries
62 Address AddressField django-address
63 Location PlainLocationField django-location-field
64 Money MoneyField django-money
65 Currency CurrencyField django-money
66 DecimalPrice DecimalField(max_digits=14, decimal_places=2)
67 StockQty PositiveIntegerField(default=0)
68 Tax DecimalField(max_digits=5, decimal_places=2)
69 Color ColorField django-colorfield
70 JSON_API JSONField
71 EncDateTime EncryptedDateTimeField django-encrypted-model-fields
72 IP2 GenericIPAddressField
73 MAC MACAddressField
74 Language LanguageField django-language-field
75 MultiCountry CountryField(multiple=True) django-countries
76 History HistoricalRecords() django-simple-history
77 AuditLog auditlog.register(self) django-auditlog
78 Reversion reversion.register(self) django-reversion
79 StatusMeta StatusField django-model-utils
80 MonitorMeta MonitorField django-model-utils
81 CIChar CICharField django-citext
82 CINullChar CINullCharField django-citext
83 JSON_API2 JSONField
84 FirstName CharField(max_length=100)
85 LastName CharField(max_length=100)
86 Username CharField(max_length=150, unique=True)
87 Bio TextField(blank=True, null=True)
88 Avatar ImageField(upload_to='avatars/')
89 Cover ImageField(upload_to='covers/')
90 BirthDate DateField(blank=True, null=True)
91 Gender CharField(choices=...)
92 LangPref CharField(max_length=20)
93 Timezone TimeZoneField django-timezone-field
94 SubStatus CharField(choices=['free','paid'])
95 NotifPref JSONField
96 Agreement BooleanField(default=False)
97 TermsVer CharField(max_length=50)
98 LastIP GenericIPAddressField
99 LastSeen DateTimeField(blank=True, null=True)
100 ActivityLog JSONField

💎 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

django_mg-1.1.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_mg-1.1.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file django_mg-1.1.1.tar.gz.

File metadata

  • Download URL: django_mg-1.1.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for django_mg-1.1.1.tar.gz
Algorithm Hash digest
SHA256 cb097cb250e542e508125f1dfb6c1370b48327b12fd8dc1f1373ce8f99bfddae
MD5 d0b8fb103f1a0b0393a5517b5594735a
BLAKE2b-256 63127d8f04c042812dddf6ca95f3dfe2a6c849a465eed865af66a66ef6a6e27c

See more details on using hashes here.

File details

Details for the file django_mg-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_mg-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for django_mg-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02199d7b349881ac05a69dc7f4e0a1998795b4d704878ff5af4c5800f722fb9b
MD5 1d532eea6cd27b00830270d4e69d6827
BLAKE2b-256 194af0f61501d9c348c769730df2390ed8c35fa8b66153d3f035e2551a25251c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page