Skip to main content

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

  1. Add extra_fields to your INSTALLED_APPS:

    In your Django project's settings.py, add extra_fields to INSTALLED_APPS:

    INSTALLED_APPS = [
        ...
        'extra_fields',
    ]
    
  2. 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)
    
  3. Migrate Your Database:

    Create and apply migrations for the new extra_fields tables:

    python manage.py makemigrations
    python manage.py migrate
    
  4. 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')
    
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_extra_model_fields-0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

django_extra_model_fields-0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file django_extra_model_fields-0.1.tar.gz.

File metadata

File hashes

Hashes for django_extra_model_fields-0.1.tar.gz
Algorithm Hash digest
SHA256 6da7f661eaee66ed4a3119343cd36558b9ba9077d320f52bce44abbb29ecffee
MD5 81346cb8d11a5062e27d7b99788e48b6
BLAKE2b-256 8f7313af37b6f700c3e44fa1afa7b13ddc373f719d9f4ac8ca21ab117cb5e514

See more details on using hashes here.

File details

Details for the file django_extra_model_fields-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_extra_model_fields-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 985b41b6c6e7433009b89534cc6f564ed2d07ebc423ab8c5c0434183d78667ce
MD5 ea26a607b7484afc8e22815a2cc35f69
BLAKE2b-256 6332acf906b7e8b2381c5c1bf972d446c6b77c3f6a6b27780f7a964e7f0bba43

See more details on using hashes here.

Supported by

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