Django: Overriding ModelAdmin save_model not working
- by tufelkinder
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?