Opened 6 years ago
Closed 6 years ago
#30006 closed Bug (duplicate)
Wrong UUID serialization in inline admin when used as a 1to1Field primary key of a UUID primary key.
Reported by: | George Cheng | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.1 |
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
Sorry for the confusing title, I create a reproducing repo on GitHub.
Key code as follows:
models.py
class Room(models.Model): id = models.UUIDField(default=uuid4, primary_key=True, editable=False) name = models.TextField() def __str__(self): return self.name class Teacher(models.Model): room = models.OneToOneField(Room, on_delete=models.CASCADE, primary_key=True) name = models.TextField() def __str__(self): return self.name class Student(models.Model): id = models.UUIDField(default=uuid4, primary_key=True, editable=False) teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE) name = models.TextField() def __str__(self): return self.name
admin.py
from .models import Room, Teacher, Student @admin.register(Room) class RoomAdmin(admin.ModelAdmin): pass @admin.register(Teacher) class TeacherAdmin(admin.ModelAdmin): class StudentInline(admin.TabularInline): model = Student inlines = [StudentInline]
Change History (3)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
>>> from app.models import * >>> Teacher.objects.last().room_id UUID('38c7b7f8-1006-467c-809b-e95546dcc58e') >>> Student.objects.last().teacher_id '38c7b7f81006467c809be95546dcc58e'
They are all UUIDs
comment:3 by , 6 years ago
Component: | contrib.admin → Database layer (models, ORM) |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Duplicate of #27595 which will be fixed in Django 2.2.
Note:
See TracTickets
for help on using tickets.
Found a workaround: add
readonly_fields = ('teachers',)
to student inline works.