I am trying to find a way to add/edit two models at once. i.e. :
class Desktop(models.Model):
#some field...
specs = models.ForeignKey(Specs)
class Specs(models.Model):
cpu = models.CharField(max_length=200)
#and some other fields
When I add a new Desktop, I want to be able to add the Specs at the same time.
With the normal Django Admin you will get an +
symbol, and you can add the values of the ForeignKey. But when you want to edit the foreignkey while editing the Desktop, you can't do it.
UPDATE! I've added the following:
class ServerInLine(admin.StackedInLine):
model = Server
extra = 1
class SpecsManager(admin.ModelAdmin):
inlines = [ServerInLine]
This makes me able to add an server when adding Specs. But actually I want to add Specs when I add a new Server. So when I add a new Server or Desktop, I want to add the specs. The specs field in Server and Desktop should then link to the specs filled in.
Try this in your admin:
class DesktopInline(admin.StackedInline):
model = Desktop
extra = 1
class SpecsAdmin(admin.ModelAdmin):
inlines = [DesktopInline,]
admin.site.register(Specs, SpecsAdmin)
take a look at the docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With