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

For the optional GUI (recommended):

pip install "django-mg[gui]"

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: Run the Generator (GUI)

python manage.py generate_model

Then type:

>>> generate.model

This will open the GUI. Choose your destination file (drop models.py or browse), select fields with checkboxes, enter ClassName, and click "تولید مدل".

Alternatively, run the GUI directly:

python -m django_mg.gui

If installed as a package, you can also run:

django-mg-gui

Step 4: 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]"

GUI Only

pip install "django-mg[gui]"

🛠️ Troubleshooting

GUI does not start

pip install "django-mg[gui]"

Then run python manage.py generate_model and type generate.model.

"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.2.tar.gz (19.5 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.2-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_mg-1.1.2.tar.gz
  • Upload date:
  • Size: 19.5 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.2.tar.gz
Algorithm Hash digest
SHA256 a03201f1d06937779a1ac2395e6488c12ed13da58704d524d810d59a6b4e708e
MD5 bfbff74e73068bc5d8926b4e06acd21c
BLAKE2b-256 11f59413c5ceeddde50f6e40a6827cad860533a817a72ae7f205a64672df8247

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_mg-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d7286af9ef35d053678a6a0399f0118ac54c94a18520662b17ad88a18c33189
MD5 a76d730e1b37c112f29ea7f4e79c67c6
BLAKE2b-256 0fd6ce3e0b0d3dea270c5ea247ebaf8b94e7aa78b59ad1e1ddc3b1f71987e157

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