#29237: Integrity Error in ModelAdmin with inlines and Foreign Key Reference
populated by models default
---------------------------------------------+------------------------
               Reporter:  Gunnar Thielebein  |          Owner:  nobody
                   Type:  Bug                |         Status:  new
              Component:  contrib.admin      |        Version:  1.11
               Severity:  Normal             |       Keywords:
           Triage Stage:  Unreviewed         |      Has patch:  0
    Needs documentation:  0                  |    Needs tests:  0
Patch needs improvement:  0                  |  Easy pickings:  0
                  UI/UX:  0                  |
---------------------------------------------+------------------------
 models.py

 {{{
 from django.db import models
 from django.contrib.auth.models import User
 import uuid

 class Pizza(models.Model):
     name = models.CharField(max_length=40, unique=True,
 verbose_name='Name')

     def __unicode__(self):
         return self.name


 class Topping(models.Model):
     name = models.CharField(max_length=40, unique=True,
 verbose_name='Name')

     def __unicode__(self):
         return self.name


 class Size(models.Model):
     size = models.CharField(max_length=40, unique=True,
 verbose_name='Size')

     def __unicode__(self):
         return self.size


 class Ordering(models.Model):
     uuid = models.UUIDField(default=uuid.uuid4, unique=True,
 editable=False, verbose_name="UUID")
     customer = models.ForeignKey('Customer', to_field='uuid',
 verbose_name='Customer')
     pizza = models.ForeignKey(Pizza, to_field='name',
 verbose_name='Pizza')
     size = models.ForeignKey(Size, to_field='size', verbose_name='Size')
     toppings = models.ManyToManyField(Topping, verbose_name='Toppings')

     def __unicode__(self):
         return str(self.uuid)

 class Customer(User):
     uuid = models.UUIDField(default=uuid.uuid4, unique=True,
 editable=False, verbose_name="UUID")
     pizzas = models.ManyToManyField(Pizza, through=Ordering, blank=True,
 verbose_name='Pizzas Ordered')

     class Meta:
         verbose_name_plural = "Customers"
 }}}

 admin.py:

 {{{
 from django.contrib import admin
 from .models import *

 from django.forms import modelformset_factory, inlineformset_factory,
 ModelForm

 OrderingFormset = inlineformset_factory(Pizza, Ordering, fields=('pizza',
 'toppings', 'size'))

 class PizzaInline(admin.TabularInline):
     model = Ordering
     formset = OrderingFormset

 class CustomerAdmin(admin.ModelAdmin):

     inlines = [
         PizzaInline,
     ]


 admin.site.register(Customer, CustomerAdmin)
 admin.site.register(Ordering)
 admin.site.register(Pizza)
 admin.site.register(Topping)
 admin.site.register(Size)
 }}}

 There is an issue when adding a new customer with the CustomerModelAdmin
 in backend.
 When creating a the following error is raised:


         IntegrityError at /admin/tabtest/customer/add/
         NOT NULL constraint failed: tabtest_customer.uuid

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29237>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.a32dcc5a4a6069189ddd7cfcca39f129%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to