I have three models
class Voting(Model):
id = ...
class Candidate(Model):
voting = ForeignKey(Voting, on_delete=DO_NOTHING)
class Commands(Model):
voting = ForeignKey(Voting, on_delete=CASCADE, verbose_name="Votación")
candidate = ForeignKey(Candidate, on_delete=CASCADE)
And I did this en model admin
class CommandInline(admin.TabularInline):
model = Commands
extra = 1
@admin.register(VotingCandidate)
class VotingCandidateAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['voting', "name"]}),
('Mensajes', {'fields': ['default_messages', 'votge_ok_mesage', 'vote_error_mesage', ], 'classes': ['collapse']}),
]
inlines = [CommandInline]
But when I press Save I get this error:
Exception Type: RelatedObjectDoesNotExist
Exception Value: Commands has no voting.
How I can put in command.voting_id the value of andidate.voting_id in order to can save one Candidate and the cmmands?
question from:
https://stackoverflow.com/questions/65907607/django-admin-connect-two-model-in-creation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…