GithubHelp home page GithubHelp logo

oskarpersson / django-nested-inline Goto Github PK

View Code? Open in Web Editor NEW
342.0 11.0 135.0 87 KB

Nested inline support for Django admin

License: MIT License

Python 38.45% CSS 8.57% JavaScript 33.49% HTML 19.49%

django-nested-inline's Introduction

django-nested-inline

Nested inline support for Django admin

Most of the code from this package is from https://code.djangoproject.com/ticket/9025

Github

https://github.com/s-block/django-nested-inline

Installation

pip install django-nested-inline

Usage

Add nested_inline to INSTALLED_APPS

# models.py

from django.db import models

class TopLevel(models.Model):
    name = models.CharField(max_length=200)

class LevelOne(models.Model):
    name = models.CharField(max_length=200)
    level = models.ForeignKey('TopLevel')

class LevelTwo(models.Model):
    name = models.CharField(max_length=200)
    level = models.ForeignKey('LevelOne')

class LevelThree(models.Model):
    name = models.CharField(max_length=200)
    level = models.ForeignKey('LevelTwo')


# admin.py

from django.contrib import admin
from nested_inline.admin import NestedStackedInline, NestedModelAdmin
from example.models import *

class LevelThreeInline(NestedStackedInline):
    model = LevelThree
    extra = 1
    fk_name = 'level'


class LevelTwoInline(NestedStackedInline):
    model = LevelTwo
    extra = 1
    fk_name = 'level'
    inlines = [LevelThreeInline]


class LevelOneInline(NestedStackedInline):
    model = LevelOne
    extra = 1
    fk_name = 'level'
    inlines = [LevelTwoInline]


class TopLevelAdmin(NestedModelAdmin):
    model = TopLevel
    inlines = [LevelOneInline]


admin.site.register(TopLevel, TopLevelAdmin)

Minifying Javascript

Released versions of this library should have a minified version of the js.

Minification is done with uglifyjs. If npm is installed on your system, you can install uglifyjs with the command:

npm install -g uglify-js

Then change to the directory where the file 'inlines-nested.js' and run the following command:

uglifyjs --compress --mangle --output ./inlines-nested.min.js -- inlines-nested.js

Releasing to PyPi

Create a file at $HOME/.pypirc and put the following text inside:

[pypi]
username = __token__
password = <Token from pypi>

Make sure the dependencies for this project are installed:

pip install django

Then install the build tool:

pip install build

Next run the distribution build of the project:

python -m build

Lastly, push the release to pypi

twine upload dist/*

Changelist

0.4.6:

  • Support django 4.1
  • Fix inline media error (#130)
  • Fix error when using 'save as new' (#149)
  • Add .fieldBox styling for django 2.1+ (#114)
  • Fix select2 import for Django >=2.2 (#150)
  • Fixed FieldDoesNotExist import to support Django>=3.2 (#147)

0.4.5 - Support django 4.0 and django-csp

0.4.4 - Add formset:added and formset:removed events (#97)

0.4.3 - Update media so it expects to find jquery in the right place. (#75)

0.4.2 - Fix assets

0.4.1 - Fix permission checks

0.4.0 - Added support for Django 3.0

0.3.7 - added support for django 1.10, fix unique fieldset id

0.3.6 - added support for django 1.9

0.3.5 - Removed deprecated methods and updated for Django 1.8/1.9

0.3.4 - added licence and updated for python 3

0.3.3 - fixed bug where inlines without inlines would cause an error

django-nested-inline's People

Contributors

andilabs avatar bashu avatar celiao avatar chrisyoulden avatar contracode avatar daniel-brenot avatar gfairchild avatar leibowitz avatar lejmr avatar lightbulbjim avatar mattflorence avatar ooppsss60 avatar oskarpersson avatar patrickbeeson avatar pawnhearts avatar petrdlouhy avatar ppython avatar rsp2k avatar s-block avatar scottgigante avatar smcoll avatar thorbenl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-nested-inline's Issues

Wrong site_header

When I set up site header through the main urls.py

from django.contrib import admin
admin.site.site_header = "TEST"

I still can see the default Django site title for models where I inherit from NestedModelAdmin.

I checked code, but I could not find how to fix this.

Leyend add new..

Hi...

How to show correct leyend?

github

I used last version.

Thanks in advance...

NestedTabularInline layout broken by "Add another..." button

The "Add another..." button, in the context of the NestedTabularInline template, is breaking the layout of the table, because the JS is inserting div.add-row after all the tr elements within the tbody, which is invalid. If it were instead inserting it after the table, inside the fieldset, the layout would be fine.

Duplicate fieldset id's when using bootstrapped causes collapse problems

The bootstrapped template admin/includes/fieldset.html assign an id attribute to each fieldset element so that it can be made to collapse amongst other things. It postfixes the id with the loop coutnter for uniqueness.

However because of the nested nature of django-nested-inline, it is easy to end up with two fieldsets of different nested objects that have the same id, for example "fieldset-1".

If then the "collapse" class is used on the fieldset, you end up collapsing more than what you intend.

Luckily the fieldset.html template allows for a prefix for the id that is used for stacked behaviour.

The fix is to pass the prefix to the fieldset.html from edit-inline/stacked-nested.html:

    {% with stacked_prefix=inline_admin_formset.formset.prefix %}
    {% for fieldset in inline_admin_form %}
    {% include "admin/includes/fieldset.html" %}
    {% endfor %}
    {% endwith %}

PyPi

Could you please make a build on PyPi with #18 to make app compatible with Python 3.

URLs for static assets are not consistent with other admin assets

If you try to use nested_inline with external static asset storage (e.g. Amazon S3) it doesn't work.
The URLs for nested inline look like:

<link href="/static/admin/css/forms-nested.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/static/admin/js/inlines-nested.js"></script>

But the other admin page URLs look like:

<script type="text/javascript" src="https://<bucketname>.s3.amazonaws.com/admin/js/core.js"></script>

So it appears that something in nested_inline is ignoring the STATICx settings.

css .aligned label miss with rtl languages original css

The problem is when dealing with rtl languages your custom css override the rtl.css file
The Only problem I have seen where with label going all the way to the left
Here is a quick fix

.aligned label {
    display: block;
    padding: 3px 10px 0 0;
    float: left; /*delete this line to fix the problem line:66*/
    width: 8em;
}

after deleting the cause of this problem float:left;

.aligned label {
    display: block;
    padding: 3px 10px 0 0;
    width: 8em;
}

This is working well with rtl languages

'LevelOnlyForm' object has no attribute 'nested_formsets'

# admin.py

    from django.contrib import admin
    from nested_inline.admin import NestedStackedInline, NestedModelAdmin
    from .models import *

    class LevelTwoInline(NestedStackedInline):
        model = LevelTwo
        extra = 1

    class LevelOneInline(NestedStackedInline):
        model = LevelOne
        extra = 1
        inlines = [LevelTwoInline]

    class LevelOnly(NestedStackedInline):
        model = LevelOnly
        extra = 1

    class TopLevelAdmin(NestedModelAdmin):
        model = TopLevel
        inlines = [LevelOneInline, LevelOnlyInline]

On save (add_view), with the above configuration, i get an error saying 'LevelOnlyForm' object has no attribute 'nested_formsets', on line 98 of admin.py. This is, of course, because no inlines are declared. Line 224 (as well as in other places) says if hasattr(inline, 'inlines'): which returns True because LevelOnlyInline.inlines = []. As a consequence, self.wrap_nested_inline_formsets() is called in a context where on line 98, form.nested_formsets doesn't exist.

That initially lead me to believe that perhaps in the case of LevelOnly, it should perhaps be defined this way:

    class LevelOnly(admin.StackedInline):
        model = LevelOnly
        extra = 1

However, in that case, on save i get 'LevelOnlyInline' object has no attribute 'inlines', presumably because NestedModelAdmin wasn't intended to handle both nested and standard inlines.

So perhaps the solution is to change if hasattr(inline, 'inlines'): to if hasattr(inline, 'inlines') and inline.inlines): or something similar, so that the check doesn't inadvertently return True.

Creating an object in an inline to an inline results into nothing

Hi again.
I've noticed a new issue :)

Create a TopLevel with some 1-st, 2-nd and 3-rd levels, save them.
Then try to create some new 1-st levels with some 2-nd and 3-rd, save them.
What is wrong: There last created 1-st levels will have no children at all.
How it would be OK: All created 1-st, 2-nd and 3-rd levels are on their places.

make Python 3 compatible

I'm running Django 1.7.1 and Python 3.4.x. I pip installed django-nested-inline, so I have 0.3.3. I was hoping to use django-nested-inline on a project I'm working on now, but it doesn't appear to be Python 3 compatible.

Traceback (most recent call last):
  File "/srv/www/swap/public_html/webapp/wsgi.py", line 39, in <module>
    application = get_wsgi_application()
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/django/contrib/admin/apps.py", line 22, in ready
    self.module.autodiscover()
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/srv/www/swap/public_html/env/lib/python3.4/site-packages/nested_inline/admin.py", line 8, in <module>
    from django.utils.encoding import force_unicode
ImportError: cannot import name 'force_unicode'

Looking at the force_unicode documentation, this is an old function call that only works under Python 2.

Loading the `cycle` tag from the `future` library is deprecated

In this file nested_inline/templates/admin/edit_inline/tabular-nested.html there load cycle from future.

This will be removed in Django 1.10.

RemovedInDjango110Warning: Loading the `cycle` tag from the `future` library is deprecated and will be removed in Django 1.10. Use the default `cycle` tag instead.
  RemovedInDjango110Warning)

Error in admin with UserAdmin

Hi,

i had to comment line 183 of nested_inline/admin.py to get it to work

 if self.all_valid_with_nesting(formsets) and form_validated:
                self.save_model(request, new_object, form, False)
                self.save_related(request, form, formsets, False)
                #self.log_addition(request, new_object)
                return self.response_add(request, new_object)
class UserAdmin(BaseUserAdmin, NestedModelAdmin):
    list_display = ('username', '__str__', 'is_staff', 'is_active' )
    inlines = [VendorInline]

admin.site.unregister(User)
admin.site.register(User, UserAdmin)

Inline + Maps: Uncaught SyntaxError: Unexpected token -

Hi, I'm using this package in combination with another package (django-easy-map) so I can add several address to a record.

I tested independently both packages and works. But when I try to use them together I have a syntax error inside the javascript of my easy-map code, due to it is trying to create a variable with the name of the id of the inline field, but this one includes dashes (i.e. "set-0-addresses_set-0-address") and of course it throws syntax errors.

extra = 0 causes impossibility to 'add another object'

This is my situation and it works fine, but if I set extra = 0 for LevelOneInline in the admin there is no row with an 'Add another LevelTwo object' button:

class LevelTwoInline(NestedStackedInline):
    model = LevelTwo
    extra = 0
    inlines = [LevelThreeInline]


class LevelOneInline(NestedStackedInline):
    model = LevelOne
    extra = 1
    inlines = [LevelTwoInline]


class TopLevelAdmin(NestedModelAdmin):
    model = TopLevel
    inlines = [LevelOneInline]

Thanks for this great lib.

Installation using pip install fails

Hi. It's me again :)

I've got both

-e git://github.com/s-block/django-chained-selectbox.git@7692b96c4c6183f2e345a8bcf3fb079c8f255df8#egg=django_chained_selectbox-dev
-e git://github.com/s-block/django-nested-inline.git@f907f0a9c18e8ec1205281ef9c198179179bd43c#egg=django_nested_inline-dev

in my requirements.txt, and besides installation fails.

Here's the trace:

Obtaining django-nested-inline from git+git://github.com/s-block/django-nested-inline.git@f907f0a9c18e8ec1205281ef9c198179179bd43c#egg=django_nested_inline-dev (from -r requirements.pip (line 14))
  Updating ./.venv/src/django-nested-inline clone (to f907f0a9c18e8ec1205281ef9c198179179bd43c)
  Could not find a tag or branch 'f907f0a9c18e8ec1205281ef9c198179179bd43c', assuming commit.
  Running setup.py egg_info for package django-nested-inline
    Traceback (most recent call last):
      File "", line 16, in 
      File "/var/www/ilim/.venv/src/django-nested-inline/setup.py", line 3, in 
        from chained_selectbox import __version__
    ImportError: No module named chained_selectbox
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "", line 16, in 

  File "/var/www/ilim/.venv/src/django-nested-inline/setup.py", line 3, in 

    from chained_selectbox import __version__

ImportError: No module named chained_selectbox

Guess some dependencies must be added to this package.

BTW, do you plan to publish this into PyPI?

Boolean field preventing model to be saved

I am trying to save a model with a boolean field at level 2.

`class Level2(models.Model):
id = models.AutoField(primary_key=True)
level1 = models.ForeignKey(Level1, blank=True, null=True)
is_correct = models.BooleanField(default=False)

class Level3(models.Model):
id = models.AutoField(primary_key=True)
type = models.CharField(max_length = 50, blank=True, null=True)
level2 = models.ForeignKey(Level2, blank=True, null=True)`

if the default value of the boolean field (false here but same when true) is kept, this leads to the following error:

save() prohibited to prevent data loss due to unsaved related object 'level 2'

however once the model has been saved i can change the value of the field without any problem.

Is this a bug or am I missing something?

Extra level 3 field on new level 2

Pip freeze:
Django==1.8.3
django-admin-bootstrapped==2.5.4
django-better-filter-widget==0.4
django-bootstrap3==6.1.0
django-nested-inline==0.3.5
wheel==0.24.0

My admin:

class MultipleChoiceOptionInlineAdmin(nested_admin.NestedStackedInline):
model = MultipleChoiceOption
extra = 0
formfield_overrides = {
models.TextField: {'widget': AdminTextInputWidget}
}

class ComprehensionQuestionInlineAdmin(nested_admin.NestedStackedInline):
model = ComprehensionQuestion
extra = 0
inlines = [MultipleChoiceOptionInlineAdmin]

class LessonAdmin(nested_admin.NestedModelAdmin):
form = LessonForm
inlines = [
ComprehensionQuestionInlineAdmin
]

When I add another Comprehension Question if one with MultipleChoiceOptions already exists, then it also has the "add another Mutliple Choice Option link and one blank Multiple Choice Option Field. The users then adds many Multiple Choice Options to the unsaved Comprehension Question. Upon clicking the Save button, the page simply jumps to the top without saving the model. I assume this is because the Comprehension Question does not exist yet.

Not sure if I messed up somewhere. If this is not a bug, please advise.

add button adds only first level inline

Hi,

Something wrong with my setup. I'm using django 1.4.5 and the lates nested-inline from git.
It creates at the start form with nested inlines without any problems. Unfortunately "add new" button doesn't work properly: it adds only first level inline.

It looks like, something incorrect in template: it creates empty-form block for first level inline and creates nothing with empty-form class for nested-inline-row.

I'm not sure if it is the problem, anyway something is incorrect. :)

raw_id field on inline not opening as modal

I've added a raw_id field to a card model inside level two of your example provided. The first inline that is being shown, opens a modal window correctly when you click on the button. If you add there another level two it also works ok, but if I want to add another level one, the raw_id field inside the level two doesn't open the modal window, it redirects me to the list of cards and doesn't allow me to select one because it is just the list.

While selecting multiple objects in m2m field it duplicates main object

I have a simple object called Poll
class Poll(models.Model): name = models.CharField(u"asd", max_length=255) allowed_groups = models.ManyToManyField(Group, blank=True)

and when i use django nested inline it creates two polls when i select 2 or more objects in allowed_groups field, it work when i remove NestedModelAdmin.

Extra 0 not working with neated inlines.

Extra 0 not working in following example

from django.contrib import admin
from nested_inline.admin import NestedStackedInline, NestedModelAdmin
from example.models import *

class LevelTwoInline(NestedStackedInline):
    model = LevelTwo
    extra = 0

class LevelOneInline(NestedStackedInline):
    model = LevelOne
    extra = 0
    inlines = [LevelTwoInline]


class TopLevelAdmin(NestedModelAdmin):
    model = TopLevel
    inlines = [LevelOneInline]


admin.site.register(TopLevel, TopLevelAdmin)

Please give me any solution.

Pip Install

I have done:

pip install -e git+git://github.com/s-block/django-nested-inline.git#egg=django-nested-inline

But when I add "nested_inline" to my INSTALLED_APPS it appears unresolved.

Have I done something wrong?

Static file error with heroku

Hi, I'd like to use nested_inline on a django instance running on heroku. Everything works great locally, but I'm getting an error on the heroku server, for some reason.

I followed the heroku guide to getting a minimal django setup working:
https://devcenter.heroku.com/articles/getting-started-with-python#introduction
So far, so good.

Then I added "django-nested-inline" to my requirements.txt, added 'nested_inline' to the end of my INSTALLED_APPS, and "from nested_inline.admin import NestedModelAdmin, NestedStackedInline" to my admin.py.

Everything still works perfectly locally, with no issues. But when I push to heroku "git push heroku master", I get the following error:
git push heroku master
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 670 bytes | 0 bytes/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: $ pip install -r requirements.txt
remote: Collecting django-nested-inline (from -r requirements.txt (line 6))
remote: Downloading django-nested-inline-0.3.6.tar.gz
remote: Installing collected packages: django-nested-inline
remote: Running setup.py install for django-nested-inline: started
remote: Running setup.py install for django-nested-inline: finished with status 'done'
remote: Successfully installed django-nested-inline-0.3.6
remote:
remote: $ python manage.py collectstatic --noinput
remote: Post-processing 'admin/css/forms-nested.css' failed!
remote: Traceback (most recent call last):
remote: File "manage.py", line 10, in
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py", line 353, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py", line 345, in execute
remote: self.fetch_command(subcommand).run_from_argv(self.argv)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
remote: self.execute(_args, *_cmd_options)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
remote: output = self.handle(_args, *_options)
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
remote: collected = self.collect()
remote: File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 128, in collect
remote: raise processed
remote: whitenoise.django.MissingFileError: The file 'admin/img/nav-bg.gif' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7f23006c2910>.
remote: The CSS file 'admin/css/forms-nested.css' references a file which could not be found:
remote: admin/img/nav-bg.gif
remote: Please check the URL references in this CSS file, particularly any
remote: relative paths which might be pointing to the wrong location.
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote: https://devcenter.heroku.com/articles/django-assets

I'm confused about why it's working differently on heroku than locally. Also, I can't find that nav-bg.gif file anywhere, but this doesn't stop nested_inline from working locally. Thanks for any tips! I realize this may be a heroku-specific issue, but I thought posting here would be more likely to reach someone who can identify the problem.

Import Error

Hi,
I am using django version 1.6.7. I encountered the below error

from django.contrib.admin.utils import unquote
ImportError: No module named utils

Inline Form Validation

I have email as unique field in database and email fields are not properly validated in inline forms.
If I gave same emails into more than one forms(inline forms), then it should give an error message like 'email already exist.' but my application get crashed.

I worked on django 1.9 and python 3.4

template not installed

While the template is in the egg. It isn't found by default. Copying it over is a solution, but I would hope it works out of the box in Django 1.8.

Not working with django1.9.

I tried to run it with django1.9 and python3 and it gives me error

TypeError at /admin/user_management/college/add/

log_addition() missing 1 required positional argument: 'message'

In django1.9 it requires three arguments.

and while installing package it installs it inside site-packages as .zip file and so templates and js files are not rendering in project.

Creating a first-level inline when not creating a master item results in error

Hi.
Here's a replay-case (I assume linux, python, and virtualenv package installed in current python environment):

cd /tmp/
mkdir django-nested-inline#1
^mkdir^cd^
virtualenv venv --no-site-packages
source venv/bin/activate
pip install Django==1.4.5
pip install -e git://github.com/s-block/django-chained-selectbox.git@7692b96c4c6183f2e345a8bcf3fb079c8f255df8#egg=django_chained_selectbox-dev
pip install -e git://github.com/s-block/django-nested-inline.git@62fb26074f04833cd972f8d4ef0e2fdddcc09eb9#egg=django_nested_inline-dev
django-admin.py startproject master
cd master
chmod +x manage.py
cp ../venv/src/django-nested-inline/example example -r
sed s/test_project// example/admin.py -i
sed s/django.db.backends./django.db.backends.sqlite3/ master/settings.py -i
sed s/\'NAME\'\:\ \'\'\,/\'NAME\'\:\ \'database.sqlite3\'\,/ master/settings.py -i
sed s/\#\ \'django.contrib.admin\'\,/\'django.contrib.admin\'\,/ master/settings.py -i
sed s/\#\ Uncomment\ the\ next\ line\ to\ enable\ admin\ documentation\:/\'nested_inline\'\,/ master/settings.py -i
sed s/\#\ \'django.contrib.admindocs\'\,/\'example\'\,/ master/settings.py -i
sed s/\#\ from\ django.contrib\ import\ admin/from\ django.contrib\ import\ admin/ master/urls.py -i
sed s/\#\ admin.autodiscover\(\)/admin.autodiscover\(\)/ master/urls.py  -i
sed s/\#\ url\(r\'\^admin\\\/\'\,\ include\(admin.site.urls\)\)\,/url\(r\'\^admin\\\/\'\,\ include\(admin.site.urls\)\)\,/ master/urls.py -i
./manage.py syncdb

./manage.py runserver

Then go to http://localhost:8000/admin/example/toplevel/new/, create new toplevel with some levels - no matter how much here, press 'Save as and continue editing'.
Then try to add new first-level, for example. You'll get here:

Environment:


Request Method: POST
Request URL: http://localhost:8002/admin/example/toplevel/2/

Django Version: 1.4.5
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'nested_inline',
 'example')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  366.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  196.             return view(request, *args, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
  224.                 return func(*args, **kwargs)
File "/home/apollov/workspaces/test/venv/src/django-nested-inline/nested_inline/admin.py" in change_view
  256.                     self.add_nested_inline_formsets(request, inline, formset)
File "/home/apollov/workspaces/test/venv/src/django-nested-inline/nested_inline/admin.py" in add_nested_inline_formsets
  68.                     self.add_nested_inline_formsets(request, nested_inline, nested_formset, depth=depth+1)
File "/home/apollov/workspaces/test/venv/src/django-nested-inline/nested_inline/admin.py" in add_nested_inline_formsets
  62.                         prefix=prefix, queryset=nested_inline.queryset(request))
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/forms/models.py" in __init__
  697.                                                 queryset=qs, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/forms/models.py" in __init__
  424.         super(BaseModelFormSet, self).__init__(**defaults)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/forms/formsets.py" in __init__
  53.         self._construct_forms()
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/forms/formsets.py" in _construct_forms
  118.             self.forms.append(self._construct_form(i))
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  706.         form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  446.                 connection=connections[self.get_queryset().db])
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
  328.             value = self.get_prep_lookup(lookup_type, value)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_lookup
  310.             return self.get_prep_value(value)
File "/home/apollov/workspaces/test/venv/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_value
  537.         return int(value)

Exception Type: ValueError at /admin/example/toplevel/2/
Exception Value: invalid literal for int() with base 10: ''

Deprecation warning - commit_on_success

I'm getting these deprecation warnings whenever I start Django.

site-packages/nested_inline/admin.py:148: RemovedInDjango18Warning: commit_on_success is deprecated in favor of atomic.
  def add_view(self, request, form_url='', extra_context=None):

site-packages/nested_inline/admin.py:242: RemovedInDjango18Warning: commit_on_success is deprecated in favor of atomic.
  def change_view(self, request, object_id, form_url='', extra_context=None):

New PyPI package

Please make new PyPI package with Django 1.10 compatibility changes.

"Parent object must be created when creating nested inlines" error when parent object has no fields other than FK

i have an intermediate model which is little more than a logical partition, so it has no fields except for an FK. See this LevelOne, for example:

class TopLevel(models.Model):
    name = models.CharField(max_length=200)

class LevelOne(models.Model):
    level = models.ForeignKey('TopLevel')

class LevelTwo(models.Model):
    name = models.CharField(max_length=200)
    level = models.ForeignKey('LevelOne')

Then with an admin configuration like this:

class LevelTwoInline(NestedStackedInline):
    model = LevelTwo
    extra = 1
    fk_name = 'level'

class LevelOneInline(NestedStackedInline):
    model = LevelOne
    extra = 1
    fk_name = 'level'
    inlines = [LevelTwoInline]

class TopLevelAdmin(NestedModelAdmin):
    model = TopLevel
    inlines = [LevelOneInline]

admin.site.register(TopLevel, TopLevelAdmin)

This appears to be due to line 141 of nested_inline/admin.py:

if (not hasattr(form, 'cleaned_data') or not form.cleaned_data) and self.formset_has_nested_data(form.nested_formsets):

form.cleaned_data is {} in this case (there are no fields to clean, other than the fk).

`ModelAdmin.save_as = True` is broken

The ModelAdmin class has a property called 'save_as', which if set to True, will include a "Save as new" button on the admin change view. When the property is added to the test project admin configuration...

class TopLevelAdmin(NestedModelAdmin):
    model = TopLevel
    inlines = [LevelOneInline]
    save_as = True

Selecting "save as new" causes an IndexError.

The default behavior for vanilla inlines attached to ModelAdmin classes with "save_as=True" seems to be that all the inlines are re-saved as new instances having all the same properties except the FK is updated to the new value.

License

There is no license type specified, is it compatible with MIT?

"object has no attribute 'inlines'" when having multiple inlines for a admin model form

The error occurs at "nested_inline/admin.py in add_view" line 178 when trying to save an object.

As an example I have these lines:

inlines = (CaseStudyTextBlockInline, CaseStudyFullWidthImageInline, CaseStudyVideoInline,
               CaseStudyImageSliderInline)

And the error is "'CaseStudyTextBlockInline' object has no attribute 'inlines'".

Am I doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.