Permalink
Browse files

Fetch the last position for the placeholder to add a correct position…

… to the new created plugin.
  • Loading branch information...
1 parent 03e7d01 commit d8b70270953dfca83e574f1032a04cb09da054ea @stephrdev stephrdev committed Aug 19, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −1 cms/api.py
View
@@ -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
@@ -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)

0 comments on commit d8b7027

Please sign in to comment.