Skip to content

Commit

Permalink
Fetch the last position for the placeholder to add a correct position…
Browse files Browse the repository at this point in the history
… to the new created plugin.
  • Loading branch information
stephrdev committed Aug 19, 2011
1 parent 03e7d01 commit d8b7027
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cms/api.py
Expand Up @@ -11,6 +11,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db.models import Max
from django.template.defaultfilters import slugify
from menus.menu_pool import menu_pool

Expand Down Expand Up @@ -266,10 +267,14 @@ def add_plugin(placeholder, plugin_type, language, position='last-child',
# validate and normalize plugin type
plugin_model, plugin_type = _verify_plugin_type(plugin_type)


max_pos = CMSPlugin.objects.filter(language=language,
placeholder=placeholder).aggregate(Max('position')).values()[0] or 0

plugin_base = CMSPlugin(
plugin_type=plugin_type,
placeholder=placeholder,
position=1,
position=max_pos + 1,
language=language
)
plugin_base.insert_at(target, position=position, save=False)
Expand Down

0 comments on commit d8b7027

Please sign in to comment.