You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to use drag-and-drop sorting in a form collection. Unfortunately, the primary key field that is updated by the sorting operation is also referenced in another (dependent or child) model in a ManyToManyField (ForeignKey would also be a problem). So when sorting changes the primary key, the relationship to the other model is broken.
For example...
class ParentCompany(models.Model):
name = models.TextField()
class Manufacturer(models.Model):
parentcompany = models.ForeignKey(ParentCompany, on_delete=models.CASCADE)
class Car(models.Model):
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)
Using drag-and-drop sorting in a form collection on the Manufacturer model could leave orphans in the Car model since primary keys that Car refers to would be changed.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to use drag-and-drop sorting in a form collection. Unfortunately, the primary key field that is updated by the sorting operation is also referenced in another (dependent or child) model in a ManyToManyField (ForeignKey would also be a problem). So when sorting changes the primary key, the relationship to the other model is broken.
For example...
Using drag-and-drop sorting in a form collection on the Manufacturer model could leave orphans in the Car model since primary keys that Car refers to would be changed.
Is there a way to use a sort field other than the primary key like the https://github.com/jrief/django-admin-sortable2 package does?
Beta Was this translation helpful? Give feedback.
All reactions