Created
November 23, 2010 09:50
-
-
Save django-rdf-tools/711535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the bug is described here http://code.djangoproject.com/ticket/12235 | |
# I tried to use the django-extensions implementation of UUIDField(), I have the same bug | |
# opened this issue for django-extensions | |
# https://github.com/django-extensions/django-extensions/issues#issue/50 | |
# | |
# I'm new to django, I just suspect that there is some code in django-admin inlines which | |
# assumes integer primary keys | |
# using : django 1.2.3 , django-extensions 0.5, PGSQL db with psycopg2 | |
# ============== | |
# in settings.py | |
# ============== | |
INSTALLED_APPS = ( | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.sites', | |
'django.contrib.messages', | |
'django.contrib.admin', | |
'django_extensions', | |
'myapp', | |
) | |
# ================== | |
# in myapp/models.py | |
# ================== | |
from django.db import models | |
from django.db.models import CharField | |
from django_extensions.db.fields import UUIDField | |
try: | |
import uuid | |
except ImportError: | |
from django_extensions.utils import uuid | |
class Worker(models.Model): | |
id = UUIDField(primary_key=True) | |
other_uuid_not_pk = UUIDField() | |
name = models.CharField(blank=True, max_length=100) | |
def __unicode__(self): | |
return(self.name) | |
class Task(models.Model): | |
id = UUIDField(primary_key=True) | |
other_uuid_not_pk = UUIDField() | |
description = models.CharField(blank=True, max_length=100) | |
workers = models.ManyToManyField(Worker, through="Todo") | |
def __unicode__(self): | |
return(self.description) | |
class Todo(models.Model): | |
id = UUIDField(primary_key=True) | |
other_uuid_not_pk = UUIDField() | |
worker = models.ForeignKey(Worker) | |
task = models.ForeignKey(Task) | |
time_allowed = models.IntegerField(default=1) | |
# ================= | |
# in myapp/admin.py | |
# ================= | |
from django.contrib import admin | |
from myapp.models import * | |
class WorkerAdmin(admin.ModelAdmin): | |
pass | |
class TodoInline(admin.TabularInline): | |
model = Todo | |
fk_name = 'task' | |
raw_id_fields = ('worker',) | |
extra = 1 | |
class TaskAdmin(admin.ModelAdmin): | |
inlines = (TodoInline,) | |
admin.site.register(Worker,WorkerAdmin) | |
admin.site.register(Task,TaskAdmin) | |
# Once synced and admin urls setup, foillow these steps to reproduce the bug : | |
# 1. Log into admin, add some workers | |
# 2. Go to Task admin, add a task, add a related worker to it, save | |
# 3. Go back to this same task admin page, and just try to save again, or add a worker and save, you got : | |
# | |
# MultiValueDictKeyError at /admin/myapp/task/c64af3b5-f6e4-11df-869c-001cb3bc281a/ | |
# "Key 'todo_set-0-id' not found in <QueryDict: .....>" | |
# | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment