Opened 11 years ago

Closed 11 years ago

#22614 closed Uncategorized (invalid)

What does the "Select a valid choice. That choice is not one of the available choices" error msg mean?

Reported by: yn Owned by: nobody
Component: Uncategorized Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Attachments (1)

Change History (2)

comment:1 by Tim Graham, 11 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top