﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
526	Error when edit_inline model have unique_together constraint	nesh <nesh [at] studioquattro [dot] co [dot] yu>	Adrian Holovaty	"Example:

{{{
#!python
class Locale(meta.Model):
    """""" available languages """"""
    locale = meta.CharField(maxlength=5, unique=True)
    encoding = meta.CharField(maxlength=50, choices=ENCODINGS, default='utf_8')
    name = meta.CharField(maxlength=200, unique=True)
    plural = meta.TextField('plural form',
                            help_text='plural form expression, see: <a href=""http://www.gnu.org/software/gettext/manual/html_node/gettext_150.html"" target=""_blank"">gettext</a>',
                            blank=True, null=True)
    nplurals = meta.PositiveSmallIntegerField('number of plural forms', blank=True, null=True)

    def __repr__(self):
        return self.name
    #

    def _manipulator_validate_plural(self, field_data, all_data):
        """""" validate plurals """"""
        field_data = field_data.strip()
        if field_data == '':
            return ''

        if all_data['nplurals'].strip() == '':
            from django.core import validators
            raise validators.ValidationError('No nplurals is defined!')

        # try to compile plural expression
        try:
            from gettext import c2py
            c2py(field_data)
        except ValueError, err:
            from django.core import validators
            raise validators.ValidationError('Plural form expression error %s' % err)
    # _manipulator_validate_plural

    class META:
        ordering = ['locale']
        admin = meta.Admin(
            fields = (
                      (None, { 'fields': ('locale', 'encoding', 'name',),}),
                      ('Plurals', { 'fields': ('nplurals', 'plural'),}),
                      ),
            list_display = ('name', 'locale', 'encoding'),
        )
    # META
# Locale

class Message(meta.Model):
    """""" messages """"""
    site = meta.ForeignKey(sites.Site, null=True)
    package = meta.ForeignKey(packages.Package, null=True)

    message = meta.CharField(maxlength=255)
    has_plural = meta.BooleanField(default=False)

    def __repr__(self):
        return self.message
    #

    class META:
        unique_together = (('site', 'package', 'message'),)
        admin = meta.Admin(
            fields = (
                      ('For', { 'fields': (('site', 'package'),),}),
                      (None, { 'fields': (('message', 'has_plural'),)}),
                      ),
            list_display = ('message', 'site', 'package', 'has_plural',),
            list_filter = ('site', 'has_plural',), #('site', 'package'),
           )
    # META
# Message

class Translation(meta.Model):
    """""" translation of the message """"""
    locale = meta.ForeignKey(Locale)
    message = meta.ForeignKey(Message, edit_inline=meta.TABULAR, num_in_admin=2, num_extra_on_change=5)
    plural = meta.PositiveIntegerField(blank=True, null=True, default=None)
    text = meta.TextField(core=True)

    def _manipulator_validate_plural(self, field_data, all_data):
        """""" validate plurals """"""
        field_data = field_data.strip()
        if field_data == '':
            return ''

        pl = int(field_data)
        locale = self.get_locale()
        message = self.get_message()

        if locale.nplurals is None:
            from django.core import validators
            raise validators.ValidationError('No plural form is defined for this locale!')

        if pl >= locale.nplurals:
            from django.core import validators
            raise validators.ValidationError('Plural form must be less than %s' % maxpl)

        if not message.has_plural:
            from django.core import validators
            raise validators.ValidationError(""Message for this translation dosen't have has_plural set"")
    # _manipulator_validate_plural

    def __repr__(self):
        if self.plural:
            return '%s[%d]: %s' % (self.get_locale().locale, self.plural, self.text)
        else:
            return '%s: %s' % (self.get_locale().locale, self.text)
    #

    class META:
        unique_together = (('locale', 'message', 'plural'),)
    # META
}}}

throws a exception in admin interface when I try to add new Message object.

{{{
There's been an error:

Traceback (most recent call last):

  File ""/Users/nesh/devel/django/django/core/handlers/base.py"", line 64, in get_response
    response = callback(request, **param_dict)

  File ""/Users/nesh/devel/django/django/views/admin/main.py"", line 766, in add_stage
    manipulator = mod.AddManipulator()

  File ""/Users/nesh/devel/django/django/utils/functional.py"", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File ""/Users/nesh/devel/django/django/core/meta/__init__.py"", line 1445, in manipulator_init
    self.fields.extend(f.get_manipulator_fields(rel_opts, self, change, name_prefix='%s.%d.' % (rel_opts.object_name.lower(), i), rel=True))

  File ""/Users/nesh/devel/django/django/core/meta/fields.py"", line 205, in get_manipulator_fields
    params['validator_list'].append(getattr(manipulator, 'isUnique%s' % '_'.join(field_name_list)))

AttributeError: MessageManipulatorAdd instance has no attribute 'isUniquelocale_message_plural'
}}}"	defect	closed	Database layer (models, ORM)	dev	major	duplicate		jeff@… nesh@… gary.wilson@…	Accepted	0	0	0	0	0	0
