I have a model PlacedOrder
that is referenced by other models using OneToOneField
and ForeignKey
. So I am using StackedTabularInline
to render it on my PlacedOrderAdmin
model.
The weird behavior is that when I start my django application I can create a new PlacedOrder
object with no problems but after that when I try to create another object the fields on the inlines are already filled with the content from the object that I just created and I can't create a new object no matter what I try, it keeps showing me the error "Please correct the errors below."
Only the fields that belongs to the inlines does that, the fields from the model PlacedOrder
are "clean". If I restart django I can see all the objects created and their data seems correct.
part of the Models:
class PlacedOrder(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4(),
editable=False
)
...
total = models.DecimalField(
_('total'),
max_digits=8,
decimal_places=2
)
class OrderStatus(models.Model):
placed_order = models.OneToOneField(
PlacedOrder,
on_delete=models.CASCADE
)
status = models.CharField(
_('status'),
choices=STATUS_CHOICES,
max_length=30,
)
Here is one of the inlines:
class OrderStatusInline(nested_admin.NestedTabularInline):
model = app_models.OrderStatus
and the Order
@admin.register(app_models.PlacedOrder)
class OrderAdmin(nested_admin.NestedModelAdmin):
inlines = (OrderStatusInline, OrderPaymentInline, OrderDeliveryInline, SelectedProductInline, )
Fixed it
So I found out that the problem had nothing to do with what I posted here, it was actually how I was declaring the id
inside PlacedOrder
.
On my original model I had the default set as uuid.uuid4()
but that was creating all the problem, once I changed it to uuid.uuid4
everything was fine.