﻿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
22614	"What does the ""Select a valid choice. That choice is not one of the available choices"" error msg mean?"	yn	nobody	"I've got en error from admin page.

I have some simple django 1.6.2 code

models.py
{{{
from django.db import models

# Create your models here.

class PhysicalProperty(models.Model):
    shortname = models.CharField(max_length=255)    
    def __str__(self):
        return self.shortname
    
class Product(models.Model):
    shortname = models.CharField(max_length=255)
    
    product_metricals = models.ManyToManyField( PhysicalProperty, through = 'ProductMetricals' )    
      
    def __str__(self):
        return self.shortname
               
from django.db.models.signals import post_save
from django.dispatch import receiver
  
@receiver(post_save, sender=Product)
def product_post_save(sender, instance, **kwargs):
    # ProductMetricals.objects.filter( product = instance ).delete()    # prev. realizaton
    
    if True: # some conditions will be here
        instance.product_metricals.clear()
   
        
class ProductMetricals(models.Model):
    amount=models.FloatField()
    product=models.ForeignKey( Product )
    physicalproperty = models.ForeignKey(PhysicalProperty )
    
    class Meta:
        unique_together = (""product"", ""physicalproperty"")
}}}

admin.py
{{{

from django.contrib import admin

# Register your models here.

from product.models import Product, ProductMetricals, PhysicalProperty

from django import forms
    
class PhysicalPropertyAdmin(admin.ModelAdmin):
    list_display = ['shortname']
    
admin.site.register(PhysicalProperty, PhysicalPropertyAdmin)

class ProductMetricalsInline(admin.TabularInline):
    model = ProductMetricals
    fieldsets = [
        (None, {'fields': ['physicalproperty','amount']}),
    ]
    extra = 2

def safe_delete(modeladmin, request, queryset):
    for i in queryset:
        i.save()

safe_delete.short_description = 'safe delete!'
    
class ProductAdmin(admin.ModelAdmin):
    fieldsets = [
        (None,               {'fields': ['shortname']}),
    ]
    inlines = [ProductMetricalsInline]
    list_display = ['shortname']
    actions = [safe_delete]
    
admin.site.register(Product, ProductAdmin)
}}}

product_post_save reciever take some conditional subdata clearing. If I makes a changes in product admin page - i've got the validation error

'Select a valid choice. That choice is not one of the available choices.'

In safe_delete admin-action all work fine.

Why I've got the 'Select a valid choice. That choice is not one of the available choices.' error?

I ask same on http://stackoverflow.com/questions/23521938/django-admin-says-select-a-valid-choice-that-choice-is-not-one-of-the-availabl, but have no answer."	Uncategorized	closed	Uncategorized	1.6	Normal	invalid			Unreviewed	0	0	0	0	0	0
