Hi!
I'm having a problem with drag'n'drop ordering of model
"PhotoSetPhotoItem". I'm using the solution with jQuery and it's
working ok (reordering) when i have a models.CharField where i manualy
write unique string (without seting it as PK). when i dont have it
reorders visualy but when i save the form in admin it rearranges them
to the initial positions. i dont understand what i s forcing them to
this ordering. please help.

jQuery snippet:
http://www.djangosnippets.org/snippets/1053/


this is my model.py

from django.db import models
from tinymce import models as tinymce_models
from filebrowser.fields import FileBrowseField
import datetime

class Photo(models.Model):
    title_hr = models.CharField('(hr)', max_length=255)
    title_en = models.CharField('(en)', max_length=255)
    slug = models.SlugField()
    description_hr = tinymce_models.HTMLField('(hr)')
    description_en = tinymce_models.HTMLField('(en)')
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now_add=True)
    img = FileBrowseField(max_length=200, initial_directory="",
extensions_allowed=['.jpg', '.jpeg', '.gif','.png'], format='Image',
blank=True, null=True)

    class Meta:
        db_table = 'media_photos'

    def __unicode__(self):
        return self.title_hr

class PhotoSet(models.Model):
    title_hr = models.CharField(max_length=255)
    title_en = models.CharField(max_length=255)
    slug = models.SlugField()
    description_hr = tinymce_models.HTMLField('(hr)')
    description_en = tinymce_models.HTMLField('(hr)')
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'media_photo_sets'

    def __unicode__(self):
        return self.title_hr

class PhotoSetPhotoItem(models.Model):
    photo_set = models.ForeignKey('PhotoSet', related_name='photoset')
    photo_item = models.ForeignKey('Photo', related_name='photoitem')
    order = models.IntegerField(blank = True, null = True)
    class Meta:
        db_table='photoset_photoitems'
        ordering = ['order']

    def __unicode__(self):
        return str(self.order)


this is my admin.py

from studiorasic.photoeditor.models import *
from django.contrib import admin
#-------------------------------------------------------
class PhotoSetPhotoItemInline(admin.StackedInline):
    model = PhotoSetPhotoItem
    raw_id_fields = ['photo_item']
    extra = 1
#-------------------------------------------------------
class PhotoSetAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title_hr',)}
    inlines = [PhotoSetPhotoItemInline]
    class Media:
        js = (
            # latest - main jquery zadnja verzija
            'js/jquery/jquery-latest.js',
            'js/jquery/ui.sortable.js',
            'js/jquery/menu-sort.js',
            'js/jquery/jquery-ui-1.7.2.custom.min.js',
        )

admin.site.register(PhotoSet, PhotoSetAdmin)
#-------------------------------------------------------
class PhotoAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title_hr',)}
    fieldsets = [
        ('Title',       {'fields': ['title_hr', 'title_en', 'slug']}),
        ('Description', {'fields': ['description_hr',
'description_en']}),
        ('Image',       {'fields': ['img']}),
    ]

admin.site.register(Photo, PhotoAdmin)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to