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'm trying to a one-to-many (e.g., one Article instance can only be part of one ArticleSeries). Can someone outline how I can do this? The docs skips over this case and go straight to many-to-many.
The text was updated successfully, but these errors were encountered:
# models.pyfromdjango.dbimportmodelsclassBook(models.Model):
# if we want to sort Books as well, add an ordering field and Meta classtitle=models.CharField("Title", max_length=255)
classSortableChapter(models.Model):
title=models.CharField("Title", max_length=255)
book=models.ForeignKey(Book, on_delete=models.CASCADE)
order=models.PositiveIntegerField(
default=0,
blank=False,
null=False,
)
classMeta:
ordering= ['order']
# models.pyfromdjango.contribimportadminfromadminsortable2.adminimportSortableStackedInline, SortableAdminBasefrom . importmodelsclassChapterStackedInline(SortableStackedInline):
model=models.SortableChapterextra=1@admin.register(models.Book)# if you to sort Books as well, use `SortableAdminMixin`classBookAdmin(SortableAdminBase, admin.ModelAdmin):
inlines= [ChapterStackedInline]
The resulting admin dashboard looks like this (don't mind the chapter names):
I'm trying to a one-to-many (e.g., one Article instance can only be part of one ArticleSeries). Can someone outline how I can do this? The docs skips over this case and go straight to many-to-many.
The text was updated successfully, but these errors were encountered: