A Django app for adding and managing extra fields on any model.
Project description
django-extra-model-fields
django-extra-model-fields
is a Django package that allows you to attach and manage additional fields on any model dynamically. This package is designed to be simple and flexible, enabling you to add key-value pairs to any Django model without modifying the original model structure.
Features
- Add custom key-value pairs to any Django model.
- Query and manage these fields easily.
- Supports Django's admin interface for easier management.
Installation
You can install django-extra-model-fields
via pip. Add it to your requirements.txt
or install it directly using pip:
pip install django-extra-model-fields
Usage
Adding to Your Django Project
-
Add extra_fields to your INSTALLED_APPS:
In your Django project's settings.py, add extra_fields to INSTALLED_APPS:
INSTALLED_APPS = [ ... 'extra_fields', ]
-
Extend Your Models:
To add extra fields to a model, make your model inherit from ExtraFieldModel:
from django.db import models from extra_fields.models import ExtraFieldModel class MyModel(ExtraFieldModel): name = models.CharField(max_length=100)
-
Migrate Your Database:
Create and apply migrations for the new extra_fields tables:
python manage.py makemigrations python manage.py migrate
-
Use the Extra Fields:
You can now use the set_extra_field, get_extra_field, and delete_extra_field methods to manage extra fields:
blog = Blog.objects.create(name="Example") blog.set_extra_field('color', 'blue') color = blog.get_extra_field('color') blog.delete_extra_field('color')
-
Add Inline editor on Admin panel
Add ExtraFieldModelInline in inlines of the model Admin
from django.contrib import admin from .models import Blog from extra_field.admin import ExtraFieldModelInline class BlogAdmin(admin.ModelAdmin): """Admin for blog model.""" list_display = ('title', 'content') inlines = [ExtraFieldModelInline] admin.site.register(Blog, BlogAdmin)
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file django_extra_model_fields-0.1.tar.gz
.
File metadata
- Download URL: django_extra_model_fields-0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6da7f661eaee66ed4a3119343cd36558b9ba9077d320f52bce44abbb29ecffee |
|
MD5 | 81346cb8d11a5062e27d7b99788e48b6 |
|
BLAKE2b-256 | 8f7313af37b6f700c3e44fa1afa7b13ddc373f719d9f4ac8ca21ab117cb5e514 |
File details
Details for the file django_extra_model_fields-0.1-py3-none-any.whl
.
File metadata
- Download URL: django_extra_model_fields-0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985b41b6c6e7433009b89534cc6f564ed2d07ebc423ab8c5c0434183d78667ce |
|
MD5 | ea26a607b7484afc8e22815a2cc35f69 |
|
BLAKE2b-256 | 6332acf906b7e8b2381c5c1bf972d446c6b77c3f6a6b27780f7a964e7f0bba43 |