Django: Overriding ModelAdmin save_model not working
Posted
by tufelkinder
on Stack Overflow
See other posts from Stack Overflow
or by tufelkinder
Published on 2010-04-05T05:26:49Z
Indexed on
2010/04/05
5:33 UTC
Read the original article
Hit count: 298
Even after obj.save(), the obj still does not have an id, so I cannot access or manipulate the m2m records. Just keep getting a "instance needs to have a primary key value before a many-to-many relationship can be used" error.
def save_model(self, request, obj, form, change):
obj.save() # this doesn't work
super(Table2Admin, self).save_model(request, obj, form, change) # still doesn't save
for tb1 in obj.table1.all:
tb1_obj = ThroughTable.objects.get(table1=bk, table2=obj)
# do other stuff
What am I doing wrong? Why do I need to do to save this model?
© Stack Overflow or respective owner