Skip to main content

A Django json field behaves as a model instance and supports seamless inline editing in Django admin.

Project description

A Django field which: works like a model instance, stores sub-model fields in single DB column, and supports smooth editing in Django admin.

django-submodel works on Django 1.3+

Installation

  1. pip install django-submodel

Usage

# in you_app/models.py

from django.db import models
from submodel.fields import SubModelField


# Define (field_name, model_field_instance) tuples in "fields" parameter in SubModelField,
#   similar as normal Model definition
# If SubModelField such as pref field is newly added to an existed model,
#   you may want to use south to migrate the schema
class UserProfile(models.Model):
    realname = models.CharField(max_length=100)
    pref = SubModelField(u'user preference',
                 fields=(
                     ('title', models.CharField(max_length=10)),
                     ('color', models.IntegerField(choices=((0, 'Black'), (1, 'White')))),
                     ('birthday_day', models.DateTimeField()),
                     ('feel_luck', models.BooleanField(default=True))))
# in you_app/admin.py, to enable editing of sub fields of pref in Django admin

from submodel.admin import SubModelFieldInlineAdmin
from . models import UserProfile

class PrefInilneAdmin(SubModelFieldInlineAdmin):
    model = UserProfile._meta.get_field('pref').submodel # TODO improve

class UserProfileAdmin(admin.ModelAdmin):
    inlines = [PrefInilneAdmin]

admin.site.register(UserProfile, UserProfileAdmin)
>>> # TODO in Python shell, the value of pref field as a model instance

TODO

  • add tests

  • simpler API

  • dump and modify Deserializer to support missing subfields. schema policy?

  • better history

  • check compatibility w/ django-reversion and others …

  • possible config

  • more strict check such as attname confliction, for example FK field user and field user_id

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

django-submodel-0.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file django-submodel-0.1.tar.gz.

File metadata

  • Download URL: django-submodel-0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-submodel-0.1.tar.gz
Algorithm Hash digest
SHA256 4c709b3a9f5809eb6231f8fb9f00f79684a1163584e970095d4eb78a3ea8d6b3
MD5 b52f3eb2ecc23055b40e443ddcd308cf
BLAKE2b-256 a999cf64277fb85ee42f511831c01137ecb2e4a66f39b12115dfbaf5992d1530

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