我有一种情况,我需要在将表单保存到 views.py 之前检查表单是否具有 m2m 关系,因为我对不同的模型使用相同的 views.py。
例子:
#models.py
class BaseClass(models.Model):
# Some generic stuff.
class SomeClass(BaseClass):
# This class doesnt have any many2many relations
class SomeOtherClass(BaseClass):
# This class has many2many relations
#views.py
def do_some_stuff(request):
# Instantiate a form
# Save it in a normal way
form.save()
# Now, in here while saving I need to check if the form has any
# m2m relations so I can use the save_m2m() function after form.save()
我只需要在那里进行额外的检查以确保安全。有没有办法解决?提前致谢