Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liokm/django-submodel
(Personally I tend to normal RDBMS solutions now...whatever) A Django json field behaves as a model instance and supports seamless inline editing in Django admin.
https://github.com/liokm/django-submodel
Last synced: about 2 months ago
JSON representation
(Personally I tend to normal RDBMS solutions now...whatever) A Django json field behaves as a model instance and supports seamless inline editing in Django admin.
- Host: GitHub
- URL: https://github.com/liokm/django-submodel
- Owner: liokm
- License: mit
- Created: 2012-03-15T11:53:33.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-03-15T19:31:30.000Z (over 12 years ago)
- Last Synced: 2024-07-24T21:11:27.144Z (2 months ago)
- Language: Python
- Homepage:
- Size: 93.8 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES
- License: LICENSE
Awesome Lists containing this project
README
===============
django-submodel
===============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
============
#. ``pip install django-submodel``
#. Add `submodel` to INSTALLED_APPS in your current settings file.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 UserProfileclass PrefInilneAdmin(SubModelFieldInlineAdmin):
model = UserProfile._meta.get_field('pref').submodel # TODO improveclass 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