2👍
Are you using the django-admin to save the model and tags? The many-to-many fields don’t get saved there until after the post-save signal of the model. What you can do in this case is overide the admin classes save_model method. E.g.:
class CardAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
obj.save()
form.save_m2m()
#from this point on the tags are accessible
print obj.tags.all()
0👍
You aren’t adding any tags to the Card. You can’t add ManyToMany relationships until after you save the Card, and there’s no time between the save
call and the call to self.tags.all()
for them to be set.
- [Answered ]-How to get parent object in multi table inheritance in django
- [Answered ]-How to create a pdf from html5 and css3 in Django?
Source:stackexchange.com