I am collecting current instance of a modeladmin class from url in admin.py as shown below. But now if I try to create a new form, it throws error because the url does not contain any id. How do I work around it in a django way? How do I get current instance of a modeladmin class in an inline class instance?
Below is my code in the inline class that throws error.
def get_object(self, request, model):
object_id = resolve(request.path).args[0] #throws index error when 'add new form is clicked'
try:
object_id = int(object_id)
except ValueError:
return None
return model.objects.get(pk=object_id)